New GCPad/Wiimote: Hopefully fixed lock up issues with DirectInput devices. Wiimote tilt should work with keyboard keys/gamepad buttons now as well as IR Forward/Backward(which was added). Made input detection buttons display "[ waiting ]" while waiting for input. minor fixes/cleanups.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5651 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak 2010-06-12 02:08:01 +00:00
parent d937b73d9c
commit ff5081942a
9 changed files with 121 additions and 70 deletions

View File

@ -15,7 +15,7 @@ namespace DirectInput
void Init( std::vector<ControllerInterface::Device*>& devices/*, HWND hwnd*/ )
{
IDirectInput8* idi8;
if ( DI_OK != DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&idi8, NULL ) )
if (FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&idi8, NULL)))
return;
#ifdef CIFACE_USE_DIRECTINPUT_KBM

View File

@ -160,11 +160,9 @@ void InitJoystick( IDirectInput8* const idi8, std::vector<ControllerInterface::D
std::vector<DIDEVICEINSTANCE> joysticks;
idi8->EnumDevices( DI8DEVCLASS_GAMECTRL, DIEnumDevicesCallback, (LPVOID)&joysticks, DIEDFL_ATTACHEDONLY );
// just a struct with an int that is set to ZERO by default
struct ZeroedInt{ZeroedInt():value(0){}unsigned int value;};
// this is used to number the joysticks
// 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>, int> name_counts;
#ifdef NO_DUPLICATE_DINPUT_XINPUT
std::vector<DWORD> xinput_guids;
@ -181,16 +179,16 @@ void InitJoystick( IDirectInput8* const idi8, std::vector<ControllerInterface::D
continue;
#endif
LPDIRECTINPUTDEVICE8 js_device;
if (DI_OK == idi8->CreateDevice(i->guidInstance, &js_device, NULL))
if (SUCCEEDED(idi8->CreateDevice(i->guidInstance, &js_device, NULL)))
{
if (DI_OK == js_device->SetDataFormat(&c_dfDIJoystick))
if (SUCCEEDED(js_device->SetDataFormat(&c_dfDIJoystick)))
{
// using foregroundwindow seems like a hack
if (DI_OK != js_device->SetCooperativeLevel(GetForegroundWindow(), DISCL_BACKGROUND | DISCL_EXCLUSIVE))
if (FAILED(js_device->SetCooperativeLevel(GetForegroundWindow(), DISCL_BACKGROUND | DISCL_EXCLUSIVE)))
{
//PanicAlert("SetCooperativeLevel(DISCL_EXCLUSIVE) failed!");
// fall back to non-exclusive mode, with no rumble
if (DI_OK != js_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))
if (FAILED(js_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
//PanicAlert("SetCooperativeLevel failed!");
js_device->Release();
@ -198,7 +196,7 @@ void InitJoystick( IDirectInput8* const idi8, std::vector<ControllerInterface::D
}
}
Joystick* js = new Joystick(/*&*i, */js_device, name_counts[i->tszInstanceName].value++);
Joystick* js = new Joystick(/*&*i, */js_device, name_counts[i->tszInstanceName]++);
// only add if it has some inputs/outpus
if (js->Inputs().size() || js->Outputs().size())
devices.push_back(js);
@ -289,7 +287,7 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
// but i guess not all devices support setting range
m_device->SetProperty( DIPROP_RANGE, &range.diph );
// so i getproperty right afterward incase it didn't set :P
if ( DI_OK == m_device->GetProperty( DIPROP_RANGE, &range.diph ) )
if (SUCCEEDED(m_device->GetProperty( DIPROP_RANGE, &range.diph)))
{
int offset = -1;
@ -333,8 +331,8 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
LONG rglDirection[] = { 0, 0 };
DICONSTANTFORCE cf = { 0 };
DIEFFECT eff;
ZeroMemory( &eff, sizeof( DIEFFECT ) );
eff.dwSize = sizeof( DIEFFECT );
ZeroMemory(&eff, sizeof(DIEFFECT));
eff.dwSize = sizeof(DIEFFECT);
eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
eff.dwDuration = INFINITE;
eff.dwGain = DI_FFNOMINALMAX;
@ -342,11 +340,11 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
eff.cAxes = std::min( (DWORD)2, (DWORD)objects.size() );
eff.rgdwAxes = rgdwAxes;
eff.rglDirection = rglDirection;
eff.cbTypeSpecificParams = sizeof( DICONSTANTFORCE );
eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
eff.lpvTypeSpecificParams = &cf;
LPDIRECTINPUTEFFECT pEffect;
if ( DI_OK == m_device->CreateEffect( GUID_ConstantForce, &eff, &pEffect, NULL ) )
if (SUCCEEDED(m_device->CreateEffect(GUID_ConstantForce, &eff, &pEffect, NULL)))
{
// temp
outputs.push_back( new Force( 0 ) );
@ -428,24 +426,27 @@ bool Joystick::UpdateInput()
else
{
DIDEVICEOBJECTDATA evtbuf[DATA_BUFFER_SIZE];
DWORD numevents = DATA_BUFFER_SIZE;
DWORD numevents;
GETDEVDATA :
numevents = DATA_BUFFER_SIZE;
hr = m_device->GetDeviceData(sizeof(*evtbuf), evtbuf, &numevents, 0);
//PanicAlert("GetDeviceData %l", hr);
while (DI_OK == hr && numevents)
if (SUCCEEDED(hr))
{
for (LPDIDEVICEOBJECTDATA evt = evtbuf; evt<evtbuf + numevents; ++evt)
for (LPDIDEVICEOBJECTDATA evt = evtbuf; evt != (evtbuf + numevents); ++evt)
{
// all the buttons are at the end of the data format
// they are bytes rather than longs
if (evt->dwOfs < DIJOFS_BUTTON(0))
*(DWORD*)(((u8*)&m_state_in) + evt->dwOfs) = evt->dwData;
*(DWORD*)(((BYTE*)&m_state_in) + evt->dwOfs) = evt->dwData;
else
*(BYTE*)(((u8*)&m_state_in) + evt->dwOfs) = (BYTE)evt->dwData;
((BYTE*)&m_state_in)[evt->dwOfs] = (BYTE)evt->dwData;
}
numevents = DATA_BUFFER_SIZE;
hr = m_device->GetDeviceData(sizeof(evtbuf), evtbuf, &numevents, 0);
// if there is more data to be received
if (DI_BUFFEROVERFLOW == hr)
goto GETDEVDATA;
}
}
@ -453,7 +454,8 @@ bool Joystick::UpdateInput()
if (DIERR_INPUTLOST == hr || DIERR_NOTACQUIRED == hr)
hr = m_device->Acquire();
return (DI_OK == hr);
return true;
//return SUCCEEDED(hr);
}
bool Joystick::UpdateOutput()
@ -479,10 +481,10 @@ bool Joystick::UpdateOutput()
eff.cbTypeSpecificParams = sizeof( cf );
eff.lpvTypeSpecificParams = &cf;
// set params and start effect
ok_count += ( DI_OK == i->iface->SetParameters( &eff, DIEP_TYPESPECIFICPARAMS | DIEP_START ) );
ok_count += SUCCEEDED(i->iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START));
}
else
ok_count += ( DI_OK == i->iface->Stop() );
ok_count += SUCCEEDED(i->iface->Stop());
}
else
++ok_count;

View File

@ -49,15 +49,15 @@ void InitKeyboardMouse( IDirectInput8* const idi8, std::vector<ControllerInterfa
LPDIRECTINPUTDEVICE8 kb_device = NULL;
LPDIRECTINPUTDEVICE8 mo_device = NULL;
if (DI_OK == idi8->CreateDevice( GUID_SysKeyboard, &kb_device, NULL))
if (SUCCEEDED(idi8->CreateDevice( GUID_SysKeyboard, &kb_device, NULL)))
{
if (DI_OK == kb_device->SetDataFormat(&c_dfDIKeyboard))
if (DI_OK == kb_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))
if (SUCCEEDED(kb_device->SetDataFormat(&c_dfDIKeyboard)))
if (SUCCEEDED(kb_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
if (DI_OK == idi8->CreateDevice( GUID_SysMouse, &mo_device, NULL ))
if (SUCCEEDED(idi8->CreateDevice( GUID_SysMouse, &mo_device, NULL )))
{
if (DI_OK == mo_device->SetDataFormat(&c_dfDIMouse2))
if (DI_OK == mo_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))
if (SUCCEEDED(mo_device->SetDataFormat(&c_dfDIMouse2)))
if (SUCCEEDED(mo_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
devices.push_back(new KeyboardMouse(kb_device, mo_device));
return;
@ -147,7 +147,7 @@ bool KeyboardMouse::UpdateInput()
if (DIERR_INPUTLOST == mo_hr || DIERR_NOTACQUIRED == mo_hr)
m_mo_device->Acquire();
if (DI_OK == kb_hr && DI_OK == mo_hr)
if (SUCCEEDED(kb_hr) && SUCCEEDED(mo_hr))
{
// need to smooth out the axes, otherwise it doesnt work for shit
for ( unsigned int i = 0; i < 3; ++i )

View File

@ -18,14 +18,11 @@ namespace ciface
namespace SDL
{
// just a struct with an int that is set to ZERO by default
struct ZeroedInt{ZeroedInt():value(0){}unsigned int value;};
void Init( std::vector<ControllerInterface::Device*>& devices )
{
// this is used to number the joysticks
// multiple joysticks with the same name shall get unique ids starting at 0
std::map<std::string, ZeroedInt> name_counts;
std::map<std::string, int> name_counts;
if (SDL_Init( SDL_INIT_FLAGS ) >= 0)
{
@ -35,7 +32,7 @@ void Init( std::vector<ControllerInterface::Device*>& devices )
SDL_Joystick* dev = SDL_JoystickOpen(i);
if ( dev )
{
Joystick* js = new Joystick(dev, i, name_counts[SDL_JoystickName(i)].value++);
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() )
devices.push_back( js );

View File

@ -384,29 +384,41 @@ void GamepadPage::ClearControl( wxCommandEvent& event )
void ControlDialog::DetectControl( wxCommandEvent& event )
{
wxButton* const btn = (wxButton*)event.GetEventObject();
// some hacks
wxChar num = ((wxButton*)event.GetEventObject())->GetLabel()[0];
if ( num > '9' )
const wxString lbl = btn->GetLabel();
wxChar num = lbl[0];
if (num > '9')
{
num = 1;
btn->SetLabel(wxT("[ waiting ]"));
}
else
{
num -= 0x30;
btn->SetLabel(wxT("w"));
}
g_plugin->controls_crit.Enter(); // enter
if ( control_reference->Detect( DETECT_WAIT_TIME, num ) ) // if we got input, update gui
if ( control_reference->Detect( DETECT_WAIT_TIME + (num - 1) * 500, num ) ) // if we got input, update gui
control_chooser->UpdateListSelection();
g_plugin->controls_crit.Leave(); // leave
btn->SetLabel(lbl);
}
void GamepadPage::DetectControl( wxCommandEvent& event )
{
ControlButton* btn = (ControlButton*)event.GetEventObject();
btn->SetLabel(wxT("[ waiting ]"));
g_plugin->controls_crit.Enter(); // enter
btn->control_reference->Detect( DETECT_WAIT_TIME );
btn->SetLabel( wxString::FromAscii( btn->control_reference->control_qualifier.name.c_str() ) );
g_plugin->controls_crit.Leave(); // leave
btn->SetLabel(wxString::FromAscii(btn->control_reference->control_qualifier.name.c_str()));
}
void ControlDialog::SelectControl( wxCommandEvent& event )

View File

@ -72,11 +72,19 @@ void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
// draw the shit
// ir cursor forward movement
if (z)
if (GROUP_TYPE_CURSOR == (*g)->control_group->type)
{
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle( 0, 64 - z*64, 64, 2);
if (z)
{
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxRED_BRUSH);
}
else
{
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxGREY_BRUSH);
}
dc.DrawRectangle( 0, 31 - z*31, 64, 2);
}
// circle for visual aid for diagonal adjustment
@ -95,19 +103,18 @@ void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
// deadzone circle
dc.SetBrush(*wxLIGHT_GREY_BRUSH);
dc.DrawCircle( 32, 32, ((*g)->control_group)->settings[0]->value * 32 );
// raw dot
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxGREY_BRUSH);
// i like the dot better than the cross i think
dc.DrawRectangle( xx - 2, yy - 2, 4, 4 );
//dc.DrawRectangle( xx-1, 64-yy-4, 2, 8 );
//dc.DrawRectangle( xx-4, 64-yy-1, 8, 2 );
}
// raw dot
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxGREY_BRUSH);
// i like the dot better than the cross i think
dc.DrawRectangle( xx - 2, yy - 2, 4, 4 );
//dc.DrawRectangle( xx-1, 64-yy-4, 2, 8 );
//dc.DrawRectangle( xx-4, 64-yy-1, 8, 2 );
// adjusted dot
if ( x!=32 || y!=32 )
if (x!=32 || y!=32)
{
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxRED_BRUSH);
@ -223,9 +230,16 @@ void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
{
ControlState trig_r = (*g)->control_group->controls[n]->control_ref->State();
// outline
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
dc.DrawRectangle(0, n*12, 64, 14);
// raw
dc.SetBrush(*wxGREY_BRUSH);
dc.DrawRectangle(0, n*12, trig_r*64, 14);
// deadzone affected
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(0, n*12, trigs[n], 14);
}

View File

@ -256,7 +256,7 @@ ControllerEmu::MixedTriggers::MixedTriggers( const char* const _name ) : Control
ControllerEmu::Triggers::Triggers( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_TRIGGERS )
{
settings.push_back( new Setting("Dead Zone", 0, 1, 50 ) );
settings.push_back( new Setting("Dead Zone", 0, 0, 50 ) );
}
ControllerEmu::Force::Force( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_FORCE )
@ -272,8 +272,11 @@ ControllerEmu::Force::Force( const char* const _name ) : ControlGroup( _name, GR
settings.push_back( new Setting("Dead Zone", 0, 0, 50 ) );
}
ControllerEmu::Tilt::Tilt( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_TILT )
ControllerEmu::Tilt::Tilt( const char* const _name )
: ControlGroup( _name, GROUP_TYPE_TILT )
{
memset(m_tilt, 0, sizeof(m_tilt));
//for ( unsigned int i = 0; i < 4; ++i )
//controls.push_back( new Input( named_directions[i] ) );
controls.push_back( new Input( "Forward" ) );
@ -289,12 +292,13 @@ ControllerEmu::Tilt::Tilt( const char* const _name ) : ControlGroup( _name, GROU
ControllerEmu::Cursor::Cursor( const char* const _name, const SWiimoteInitialize* const _wiimote_initialize )
: ControlGroup( _name, GROUP_TYPE_CURSOR )
//, z(0)
, wiimote_initialize(_wiimote_initialize)
, m_z(0)
{
for ( unsigned int i = 0; i < 4; ++i )
controls.push_back( new Input( named_directions[i] ) );
controls.push_back( new Input( "Forward" ) );
controls.push_back( new Input( "Backward" ) );
controls.push_back( new Input( "Hide" ) );
settings.push_back( new Setting("Center", 0.5f ) );

View File

@ -307,9 +307,23 @@ public:
xx = std::max( -1.0f, std::min( 1.0f, ang_cos * dist ) );
}
*y = C( yy * range + base );
*x = C( xx * range + base );
// this is kinda silly here
// gui being open will make this happen 2x as fast, o well
if (xx > m_tilt[0])
m_tilt[0] = std::min(m_tilt[0] + 0.1f, xx);
else if (xx < m_tilt[0])
m_tilt[0] = std::max(m_tilt[0] - 0.1f, xx);
if (yy > m_tilt[1])
m_tilt[1] = std::min(m_tilt[1] + 0.1f, yy);
else if (yy < m_tilt[1])
m_tilt[1] = std::max(m_tilt[1] - 0.1f, yy);
*y = C( m_tilt[1] * range + base );
*x = C( m_tilt[0] * range + base );
}
private:
float m_tilt[2];
};
class Cursor : public ControlGroup
@ -318,18 +332,25 @@ public:
Cursor( const char* const _name, const SWiimoteInitialize* const _wiimote_initialize );
template <typename C>
void GetState( C* const x, C* const y, C* const forward, const bool adjusted = false )
void GetState( C* const x, C* const y, C* const z, const bool adjusted = false )
{
const ControlState z = controls[4]->control_ref->State();
const float zz = controls[4]->control_ref->State() - controls[5]->control_ref->State();
// silly being here
if (zz > m_z)
m_z = std::min(m_z + 0.1f, zz);
else if (zz < m_z)
m_z = std::max(m_z - 0.1f, zz);
*z = m_z;
// hide
if (controls[5]->control_ref->State() > 0.5f)
if (controls[6]->control_ref->State() > 0.5f)
{
*x = 10000; *y = 0; *forward = 0;
*x = 10000; *y = 0;
}
else
{
*forward = z;
float xx, yy;
GetMousePos(xx, yy, wiimote_initialize);
@ -359,6 +380,7 @@ public:
private:
const SWiimoteInitialize* const wiimote_initialize;
float m_z;
};
class Extension : public ControlGroup

View File

@ -498,7 +498,7 @@ void Wiimote::Update()
yy *= (-256 * 0.90f);
yy += 490;
const unsigned int distance = (unsigned int)(100 + 100 * zz);
const unsigned int distance = (unsigned int)(200 + 100 * zz);
// TODO: make roll affect the dot positions
const unsigned int y = (unsigned int)yy;
@ -509,13 +509,13 @@ void Wiimote::Update()
x[2] = (unsigned int)(xx - 1.2f * distance);
x[3] = (unsigned int)(xx + 1.2f * distance);
//0xFF report
// 0xFF report / these memsets are silly
if (rpt.ext)
memset(data + rpt.ir, 0xFF, (rpt.ext - rpt.ir));
else
memset(data + rpt.ir, 0xFF, (46 - rpt.ir));
//Fill report with valid data when full handshake was done
// Fill report with valid data when full handshake was done
if (m_reg_ir->data[0x30] || m_reg_ir->data[0x33])
// ir mode
switch (m_reg_ir->mode)