cleanup
This commit is contained in:
@@ -28,20 +28,18 @@ bool DIDevice::Open()
|
|||||||
buffered = true;
|
buffered = true;
|
||||||
|
|
||||||
LPDIRECTINPUTDEVICE tmpdevice;
|
LPDIRECTINPUTDEVICE tmpdevice;
|
||||||
HRESULT hr = IDirectInput_CreateDevice(dinput, JoystickInst.guidInstance,
|
HRESULT hr = dinput->CreateDevice( JoystickInst.guidInstance, &tmpdevice, NULL );
|
||||||
&tmpdevice, NULL);
|
|
||||||
if ( hr != DI_OK )
|
if ( hr != DI_OK )
|
||||||
{
|
{
|
||||||
LOG->Info( hr_ssprintf(hr, "OpenDevice: IDirectInput_CreateDevice") );
|
LOG->Info( hr_ssprintf(hr, "OpenDevice: IDirectInput_CreateDevice") );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = IDirectInputDevice_QueryInterface(tmpdevice,
|
hr = tmpdevice->QueryInterface( IID_IDirectInputDevice2, (LPVOID *) &Device );
|
||||||
IID_IDirectInputDevice2, (LPVOID *) &Device);
|
tmpdevice->Release();
|
||||||
IDirectInputDevice_Release(tmpdevice);
|
|
||||||
if ( hr != DI_OK )
|
if ( hr != DI_OK )
|
||||||
{
|
{
|
||||||
LOG->Info( hr_ssprintf(hr, "OpenDevice(%s): IDirectInputDevice_QueryInterface", JoystickInst.tszProductName) );
|
LOG->Info( hr_ssprintf(hr, "OpenDevice(%s): IDirectInputDevice::QueryInterface", JoystickInst.tszProductName) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,26 +47,24 @@ bool DIDevice::Open()
|
|||||||
if( type == KEYBOARD )
|
if( type == KEYBOARD )
|
||||||
coop = DISCL_FOREGROUND|DISCL_NONEXCLUSIVE;
|
coop = DISCL_FOREGROUND|DISCL_NONEXCLUSIVE;
|
||||||
|
|
||||||
hr = IDirectInputDevice2_SetCooperativeLevel( Device, g_hWndMain, coop );
|
hr = Device->SetCooperativeLevel( g_hWndMain, coop );
|
||||||
if ( hr != DI_OK )
|
if ( hr != DI_OK )
|
||||||
{
|
{
|
||||||
LOG->Info( hr_ssprintf(hr, "OpenDevice(%s): IDirectInputDevice2_SetCooperativeLevel", JoystickInst.tszProductName) );
|
LOG->Info( hr_ssprintf(hr, "OpenDevice(%s): IDirectInputDevice2::SetCooperativeLevel", JoystickInst.tszProductName) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = IDirectInputDevice2_SetDataFormat(Device,
|
hr = Device->SetDataFormat( type == JOYSTICK? &c_dfDIJoystick: &c_dfDIKeyboard );
|
||||||
type == JOYSTICK? &c_dfDIJoystick: &c_dfDIKeyboard);
|
|
||||||
if ( hr != DI_OK )
|
if ( hr != DI_OK )
|
||||||
{
|
{
|
||||||
LOG->Info( hr_ssprintf(hr, "OpenDevice(%s): IDirectInputDevice2_SetDataFormat", JoystickInst.tszProductName) );
|
LOG->Info( hr_ssprintf(hr, "OpenDevice(%s): IDirectInputDevice2::SetDataFormat", JoystickInst.tszProductName) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( type )
|
switch( type )
|
||||||
{
|
{
|
||||||
case JOYSTICK:
|
case JOYSTICK:
|
||||||
IDirectInputDevice2_EnumObjects(Device, DIJoystick_EnumDevObjectsProc,
|
Device->EnumObjects( DIJoystick_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
|
||||||
this, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
|
|
||||||
break;
|
break;
|
||||||
case KEYBOARD:
|
case KEYBOARD:
|
||||||
/* Always 256-button. */
|
/* Always 256-button. */
|
||||||
@@ -93,15 +89,14 @@ bool DIDevice::Open()
|
|||||||
dipdw.diph.dwObj = 0;
|
dipdw.diph.dwObj = 0;
|
||||||
dipdw.diph.dwHow = DIPH_DEVICE;
|
dipdw.diph.dwHow = DIPH_DEVICE;
|
||||||
dipdw.dwData = INPUT_QSIZE;
|
dipdw.dwData = INPUT_QSIZE;
|
||||||
hr = IDirectInputDevice2_SetProperty(Device,
|
hr = Device->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph );
|
||||||
DIPROP_BUFFERSIZE, &dipdw.diph);
|
|
||||||
if ( hr == DI_POLLEDDEVICE )
|
if ( hr == DI_POLLEDDEVICE )
|
||||||
{
|
{
|
||||||
/* This device doesn't support buffering, so we're forced
|
/* This device doesn't support buffering, so we're forced
|
||||||
* to use less reliable polling. */
|
* to use less reliable polling. */
|
||||||
buffered = false;
|
buffered = false;
|
||||||
} else if ( hr != DI_OK ) {
|
} else if ( hr != DI_OK ) {
|
||||||
LOG->Info( hr_ssprintf(hr, "OpenDevice(%s): IDirectInputDevice2_SetProperty", JoystickInst.tszProductName) );
|
LOG->Info( hr_ssprintf(hr, "OpenDevice(%s): IDirectInputDevice2::SetProperty", JoystickInst.tszProductName) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,8 +109,8 @@ void DIDevice::Close()
|
|||||||
/* Don't try to close a device that isn't open. */
|
/* Don't try to close a device that isn't open. */
|
||||||
ASSERT( Device != NULL );
|
ASSERT( Device != NULL );
|
||||||
|
|
||||||
IDirectInputDevice2_Unacquire(Device);
|
Device->Unacquire();
|
||||||
IDirectInputDevice2_Release(Device);
|
Device->Release();
|
||||||
|
|
||||||
Device = NULL;
|
Device = NULL;
|
||||||
buttons = axes = hats = NULL;
|
buttons = axes = hats = NULL;
|
||||||
@@ -159,7 +154,7 @@ static BOOL CALLBACK DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev
|
|||||||
diprg.lMin = -100;
|
diprg.lMin = -100;
|
||||||
diprg.lMax = 100;
|
diprg.lMax = 100;
|
||||||
|
|
||||||
hr = IDirectInputDevice2_SetProperty(device->Device, DIPROP_RANGE, &diprg.diph);
|
hr = device->Device->SetProperty( DIPROP_RANGE, &diprg.diph );
|
||||||
if ( hr != DI_OK )
|
if ( hr != DI_OK )
|
||||||
return DIENUM_CONTINUE; /* don't use this axis */
|
return DIENUM_CONTINUE; /* don't use this axis */
|
||||||
|
|
||||||
@@ -169,7 +164,7 @@ static BOOL CALLBACK DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev
|
|||||||
dilong.diph.dwObj = dev->dwOfs;
|
dilong.diph.dwObj = dev->dwOfs;
|
||||||
dilong.diph.dwHow = DIPH_BYOFFSET;
|
dilong.diph.dwHow = DIPH_BYOFFSET;
|
||||||
dilong.dwData = 0;
|
dilong.dwData = 0;
|
||||||
hr = IDirectInputDevice2_SetProperty(device->Device, DIPROP_DEADZONE, &dilong.diph);
|
hr = device->Device->SetProperty( DIPROP_DEADZONE, &dilong.diph );
|
||||||
if ( hr != DI_OK )
|
if ( hr != DI_OK )
|
||||||
return DIENUM_CONTINUE; /* don't use this axis */
|
return DIENUM_CONTINUE; /* don't use this axis */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user