style
This commit is contained in:
@@ -82,17 +82,17 @@ InputHandler_DInput::InputHandler_DInput()
|
|||||||
|
|
||||||
AppInstance inst;
|
AppInstance inst;
|
||||||
HRESULT hr = DirectInputCreate(inst.Get(), DIRECTINPUT_VERSION, &dinput, NULL);
|
HRESULT hr = DirectInputCreate(inst.Get(), DIRECTINPUT_VERSION, &dinput, NULL);
|
||||||
if ( hr != DI_OK )
|
if( hr != DI_OK )
|
||||||
RageException::Throw( hr_ssprintf(hr, "InputHandler_DInput: DirectInputCreate") );
|
RageException::Throw( hr_ssprintf(hr, "InputHandler_DInput: DirectInputCreate") );
|
||||||
|
|
||||||
LOG->Trace( "InputHandler_DInput: IDirectInput::EnumDevices(DIDEVTYPE_KEYBOARD)" );
|
LOG->Trace( "InputHandler_DInput: IDirectInput::EnumDevices(DIDEVTYPE_KEYBOARD)" );
|
||||||
hr = dinput->EnumDevices( DIDEVTYPE_KEYBOARD, EnumDevices, NULL, DIEDFL_ATTACHEDONLY );
|
hr = dinput->EnumDevices( DIDEVTYPE_KEYBOARD, EnumDevices, NULL, DIEDFL_ATTACHEDONLY );
|
||||||
if ( hr != DI_OK )
|
if( hr != DI_OK )
|
||||||
RageException::Throw( hr_ssprintf(hr, "InputHandler_DInput: IDirectInput::EnumDevices") );
|
RageException::Throw( hr_ssprintf(hr, "InputHandler_DInput: IDirectInput::EnumDevices") );
|
||||||
|
|
||||||
LOG->Trace( "InputHandler_DInput: IDirectInput::EnumDevices(DIDEVTYPE_JOYSTICK)" );
|
LOG->Trace( "InputHandler_DInput: IDirectInput::EnumDevices(DIDEVTYPE_JOYSTICK)" );
|
||||||
hr = dinput->EnumDevices( DIDEVTYPE_JOYSTICK, EnumDevices, NULL, DIEDFL_ATTACHEDONLY );
|
hr = dinput->EnumDevices( DIDEVTYPE_JOYSTICK, EnumDevices, NULL, DIEDFL_ATTACHEDONLY );
|
||||||
if ( hr != DI_OK )
|
if( hr != DI_OK )
|
||||||
RageException::Throw( hr_ssprintf(hr, "InputHandler_DInput: IDirectInput::EnumDevices") );
|
RageException::Throw( hr_ssprintf(hr, "InputHandler_DInput: IDirectInput::EnumDevices") );
|
||||||
|
|
||||||
for( unsigned i = 0; i < Devices.size(); ++i )
|
for( unsigned i = 0; i < Devices.size(); ++i )
|
||||||
@@ -136,9 +136,9 @@ void InputHandler_DInput::ShutdownThread()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_bShutdown = true;
|
m_bShutdown = true;
|
||||||
LOG->Trace("Shutting down DirectInput thread ...");
|
LOG->Trace( "Shutting down DirectInput thread ..." );
|
||||||
m_Thread.Wait();
|
m_Thread.Wait();
|
||||||
LOG->Trace("DirectInput thread shut down.");
|
LOG->Trace( "DirectInput thread shut down." );
|
||||||
m_bShutdown = false;
|
m_bShutdown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ InputHandler_DInput::~InputHandler_DInput()
|
|||||||
Devices[i].Close();
|
Devices[i].Close();
|
||||||
|
|
||||||
Devices.clear();
|
Devices.clear();
|
||||||
IDirectInput_Release(dinput);
|
dinput->Release();
|
||||||
dinput = NULL;
|
dinput = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ static HRESULT GetDeviceState( LPDIRECTINPUTDEVICE2 dev, int size, void *ptr )
|
|||||||
|
|
||||||
/* This doesn't take a timestamp; instead, we let InputHandler::ButtonPressed figure
|
/* This doesn't take a timestamp; instead, we let InputHandler::ButtonPressed figure
|
||||||
* it out. Be sure to call InputHandler::Update() between each poll. */
|
* it out. Be sure to call InputHandler::Update() between each poll. */
|
||||||
void InputHandler_DInput::UpdatePolled(DIDevice &device, const RageTimer &tm)
|
void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
|
||||||
{
|
{
|
||||||
switch( device.type )
|
switch( device.type )
|
||||||
{
|
{
|
||||||
@@ -241,11 +241,11 @@ void InputHandler_DInput::UpdatePolled(DIDevice &device, const RageTimer &tm)
|
|||||||
{
|
{
|
||||||
unsigned char keys[256];
|
unsigned char keys[256];
|
||||||
|
|
||||||
HRESULT hr = GetDeviceState(device.Device, 256, keys);
|
HRESULT hr = GetDeviceState( device.Device, 256, keys );
|
||||||
if ( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED )
|
if( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( hr != DI_OK )
|
if( hr != DI_OK )
|
||||||
{
|
{
|
||||||
LOG->MapLog( "UpdatePolled", hr_ssprintf(hr, "Failures on polled keyboard update") );
|
LOG->MapLog( "UpdatePolled", hr_ssprintf(hr, "Failures on polled keyboard update") );
|
||||||
return;
|
return;
|
||||||
@@ -263,11 +263,11 @@ void InputHandler_DInput::UpdatePolled(DIDevice &device, const RageTimer &tm)
|
|||||||
DIJOYSTATE state;
|
DIJOYSTATE state;
|
||||||
|
|
||||||
HRESULT hr = GetDeviceState(device.Device, sizeof(state), &state);
|
HRESULT hr = GetDeviceState(device.Device, sizeof(state), &state);
|
||||||
if ( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED )
|
if( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Set each known axis, button and POV. */
|
/* Set each known axis, button and POV. */
|
||||||
for(unsigned i = 0; i < device.Inputs.size(); ++i)
|
for( unsigned i = 0; i < device.Inputs.size(); ++i )
|
||||||
{
|
{
|
||||||
const input_t &in = device.Inputs[i];
|
const input_t &in = device.Inputs[i];
|
||||||
const InputDevice dev = device.dev;
|
const InputDevice dev = device.dev;
|
||||||
@@ -276,8 +276,8 @@ void InputHandler_DInput::UpdatePolled(DIDevice &device, const RageTimer &tm)
|
|||||||
{
|
{
|
||||||
case in.BUTTON:
|
case in.BUTTON:
|
||||||
{
|
{
|
||||||
DeviceInput di(dev, (DeviceButton) (JOY_BUTTON_1 + in.num), -1, tm);
|
DeviceInput di( dev, enum_add2(JOY_BUTTON_1, in.num), -1, tm );
|
||||||
ButtonPressed(di, !!state.rgbButtons[in.ofs - DIJOFS_BUTTON0]);
|
ButtonPressed( di, !!state.rgbButtons[in.ofs - DIJOFS_BUTTON0] );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ void InputHandler_DInput::UpdatePolled(DIDevice &device, const RageTimer &tm)
|
|||||||
{
|
{
|
||||||
DeviceButton neg = DeviceButton_Invalid, pos = DeviceButton_Invalid;
|
DeviceButton neg = DeviceButton_Invalid, pos = DeviceButton_Invalid;
|
||||||
int val = 0;
|
int val = 0;
|
||||||
switch(in.ofs)
|
switch( in.ofs )
|
||||||
{
|
{
|
||||||
case DIJOFS_X: neg = JOY_LEFT; pos = JOY_RIGHT;
|
case DIJOFS_X: neg = JOY_LEFT; pos = JOY_RIGHT;
|
||||||
val = state.lX;
|
val = state.lX;
|
||||||
@@ -313,7 +313,7 @@ void InputHandler_DInput::UpdatePolled(DIDevice &device, const RageTimer &tm)
|
|||||||
neg = JOY_AUX_3; pos = JOY_AUX_4;
|
neg = JOY_AUX_3; pos = JOY_AUX_4;
|
||||||
val = state.rglSlider[1];
|
val = state.rglSlider[1];
|
||||||
break;
|
break;
|
||||||
default: LOG->MapLog("unknown input",
|
default: LOG->MapLog( "unknown input",
|
||||||
"Controller '%s' is returning an unknown joystick offset, %i",
|
"Controller '%s' is returning an unknown joystick offset, %i",
|
||||||
device.JoystickInst.tszProductName, in.ofs );
|
device.JoystickInst.tszProductName, in.ofs );
|
||||||
continue;
|
continue;
|
||||||
@@ -331,11 +331,11 @@ void InputHandler_DInput::UpdatePolled(DIDevice &device, const RageTimer &tm)
|
|||||||
case in.HAT:
|
case in.HAT:
|
||||||
if( in.num == 0 )
|
if( in.num == 0 )
|
||||||
{
|
{
|
||||||
const int pos = TranslatePOV(state.rgdwPOV[in.ofs - DIJOFS_POV(0)]);
|
const int pos = TranslatePOV( state.rgdwPOV[in.ofs - DIJOFS_POV(0)] );
|
||||||
ButtonPressed(DeviceInput(dev, JOY_HAT_UP, -1, tm), !!(pos & HAT_UP_MASK));
|
ButtonPressed( DeviceInput(dev, JOY_HAT_UP, -1, tm), !!(pos & HAT_UP_MASK) );
|
||||||
ButtonPressed(DeviceInput(dev, JOY_HAT_DOWN, -1, tm), !!(pos & HAT_DOWN_MASK));
|
ButtonPressed( DeviceInput(dev, JOY_HAT_DOWN, -1, tm), !!(pos & HAT_DOWN_MASK) );
|
||||||
ButtonPressed(DeviceInput(dev, JOY_HAT_LEFT, -1, tm), !!(pos & HAT_LEFT_MASK));
|
ButtonPressed( DeviceInput(dev, JOY_HAT_LEFT, -1, tm), !!(pos & HAT_LEFT_MASK) );
|
||||||
ButtonPressed(DeviceInput(dev, JOY_HAT_RIGHT, -1, tm), !!(pos & HAT_RIGHT_MASK));
|
ButtonPressed( DeviceInput(dev, JOY_HAT_RIGHT, -1, tm), !!(pos & HAT_RIGHT_MASK) );
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -346,18 +346,18 @@ void InputHandler_DInput::UpdatePolled(DIDevice &device, const RageTimer &tm)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler_DInput::UpdateBuffered(DIDevice &device, const RageTimer &tm)
|
void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm )
|
||||||
{
|
{
|
||||||
DWORD numevents;
|
DWORD numevents;
|
||||||
DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE];
|
DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE];
|
||||||
|
|
||||||
numevents = INPUT_QSIZE;
|
numevents = INPUT_QSIZE;
|
||||||
HRESULT hr = IDirectInputDevice2_GetDeviceData( device.Device, sizeof(DIDEVICEOBJECTDATA), evtbuf, &numevents, 0);
|
HRESULT hr = device.Device->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), evtbuf, &numevents, 0);
|
||||||
if ( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED )
|
if( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Handle the events */
|
/* Handle the events */
|
||||||
if ( hr != DI_OK )
|
if( hr != DI_OK )
|
||||||
{
|
{
|
||||||
LOG->Trace( hr_ssprintf(hr, "UpdateBuffered: IDirectInputDevice2_GetDeviceData") );
|
LOG->Trace( hr_ssprintf(hr, "UpdateBuffered: IDirectInputDevice2_GetDeviceData") );
|
||||||
return;
|
return;
|
||||||
@@ -368,24 +368,24 @@ void InputHandler_DInput::UpdateBuffered(DIDevice &device, const RageTimer &tm)
|
|||||||
if( GetForegroundWindow() != GraphicsWindow::GetHwnd() )
|
if( GetForegroundWindow() != GraphicsWindow::GetHwnd() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(int i = 0; i < (int) numevents; ++i)
|
for( int i = 0; i < (int) numevents; ++i )
|
||||||
{
|
{
|
||||||
for(unsigned j = 0; j < device.Inputs.size(); ++j)
|
for(unsigned j = 0; j < device.Inputs.size(); ++j)
|
||||||
{
|
{
|
||||||
const input_t &in = device.Inputs[j];
|
const input_t &in = device.Inputs[j];
|
||||||
const InputDevice dev = device.dev;
|
const InputDevice dev = device.dev;
|
||||||
|
|
||||||
if(evtbuf[i].dwOfs != in.ofs)
|
if( evtbuf[i].dwOfs != in.ofs )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch(in.type)
|
switch( in.type )
|
||||||
{
|
{
|
||||||
case in.KEY:
|
case in.KEY:
|
||||||
ButtonPressed(DeviceInput(dev, (DeviceButton) in.num, -1, tm), !!(evtbuf[i].dwData & 0x80));
|
ButtonPressed( DeviceInput(dev, (DeviceButton) in.num, -1, tm), !!(evtbuf[i].dwData & 0x80)) ;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case in.BUTTON:
|
case in.BUTTON:
|
||||||
ButtonPressed(DeviceInput(dev, enum_add2(JOY_BUTTON_1, in.num), -1, tm), !!evtbuf[i].dwData);
|
ButtonPressed( DeviceInput(dev, enum_add2(JOY_BUTTON_1, in.num), -1, tm), !!evtbuf[i].dwData );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case in.AXIS:
|
case in.AXIS:
|
||||||
@@ -401,24 +401,24 @@ void InputHandler_DInput::UpdateBuffered(DIDevice &device, const RageTimer &tm)
|
|||||||
case DIJOFS_RZ: up = JOY_ROT_Z_UP; down = JOY_ROT_Z_DOWN; break;
|
case DIJOFS_RZ: up = JOY_ROT_Z_UP; down = JOY_ROT_Z_DOWN; break;
|
||||||
case DIJOFS_SLIDER(0): up = JOY_AUX_1; down = JOY_AUX_2; break;
|
case DIJOFS_SLIDER(0): up = JOY_AUX_1; down = JOY_AUX_2; break;
|
||||||
case DIJOFS_SLIDER(1): up = JOY_AUX_3; down = JOY_AUX_4; break;
|
case DIJOFS_SLIDER(1): up = JOY_AUX_3; down = JOY_AUX_4; break;
|
||||||
default: LOG->MapLog("unknown input",
|
default: LOG->MapLog( "unknown input",
|
||||||
"Controller '%s' is returning an unknown joystick offset, %i",
|
"Controller '%s' is returning an unknown joystick offset, %i",
|
||||||
device.JoystickInst.tszProductName, in.ofs );
|
device.JoystickInst.tszProductName, in.ofs );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float l = SCALE( int(evtbuf[i].dwData), 0.0f, 100.0f, 0.0f, 1.0f );
|
float l = SCALE( int(evtbuf[i].dwData), 0.0f, 100.0f, 0.0f, 1.0f );
|
||||||
ButtonPressed(DeviceInput(dev, up, max(-l,0), tm), int(evtbuf[i].dwData) < -50);
|
ButtonPressed( DeviceInput(dev, up, max(-l,0), tm), int(evtbuf[i].dwData) < -50 );
|
||||||
ButtonPressed(DeviceInput(dev, down, max(+l,0), tm), int(evtbuf[i].dwData) > 50);
|
ButtonPressed( DeviceInput(dev, down, max(+l,0), tm), int(evtbuf[i].dwData) > 50 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case in.HAT:
|
case in.HAT:
|
||||||
{
|
{
|
||||||
const int pos = TranslatePOV(evtbuf[i].dwData);
|
const int pos = TranslatePOV( evtbuf[i].dwData );
|
||||||
ButtonPressed(DeviceInput(dev, JOY_HAT_UP, -1, tm), !!(pos & HAT_UP_MASK));
|
ButtonPressed( DeviceInput(dev, JOY_HAT_UP, -1, tm), !!(pos & HAT_UP_MASK) );
|
||||||
ButtonPressed(DeviceInput(dev, JOY_HAT_DOWN, -1, tm), !!(pos & HAT_DOWN_MASK));
|
ButtonPressed( DeviceInput(dev, JOY_HAT_DOWN, -1, tm), !!(pos & HAT_DOWN_MASK) );
|
||||||
ButtonPressed(DeviceInput(dev, JOY_HAT_LEFT, -1, tm), !!(pos & HAT_LEFT_MASK));
|
ButtonPressed( DeviceInput(dev, JOY_HAT_LEFT, -1, tm), !!(pos & HAT_LEFT_MASK) );
|
||||||
ButtonPressed(DeviceInput(dev, JOY_HAT_RIGHT, -1, tm), !!(pos & HAT_RIGHT_MASK));
|
ButtonPressed( DeviceInput(dev, JOY_HAT_RIGHT, -1, tm), !!(pos & HAT_RIGHT_MASK) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -434,15 +434,15 @@ void InputHandler_DInput::PollAndAcquireDevices( bool bBuffered )
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
HRESULT hr = IDirectInputDevice2_Poll( Devices[i].Device );
|
HRESULT hr = IDirectInputDevice2_Poll( Devices[i].Device );
|
||||||
if ( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED )
|
if( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED )
|
||||||
{
|
{
|
||||||
/* This will fail with "access denied" on the keyboard if we don't
|
/* This will fail with "access denied" on the keyboard if we don't
|
||||||
* have focus. */
|
* have focus. */
|
||||||
hr = IDirectInputDevice2_Acquire( Devices[i].Device );
|
hr = Devices[i].Device->Acquire();
|
||||||
if ( hr != DI_OK )
|
if( hr != DI_OK )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
IDirectInputDevice2_Poll( Devices[i].Device );
|
Devices[i].Device->Poll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,7 +489,7 @@ void InputHandler_DInput::InputThreadMain()
|
|||||||
SetThreadPriorityBoost( GetCurrentThread(), FALSE );
|
SetThreadPriorityBoost( GetCurrentThread(), FALSE );
|
||||||
|
|
||||||
vector<DIDevice*> BufferedDevices;
|
vector<DIDevice*> BufferedDevices;
|
||||||
HANDLE Handle = CreateEvent(NULL, FALSE, FALSE, NULL);
|
HANDLE Handle = CreateEvent( NULL, FALSE, FALSE, NULL );
|
||||||
for( unsigned i = 0; i < Devices.size(); ++i )
|
for( unsigned i = 0; i < Devices.size(); ++i )
|
||||||
{
|
{
|
||||||
if( !Devices[i].buffered )
|
if( !Devices[i].buffered )
|
||||||
@@ -497,11 +497,11 @@ void InputHandler_DInput::InputThreadMain()
|
|||||||
|
|
||||||
BufferedDevices.push_back( &Devices[i] );
|
BufferedDevices.push_back( &Devices[i] );
|
||||||
|
|
||||||
IDirectInputDevice2_Unacquire(Devices[i].Device);
|
Devices[i].Device->Unacquire();
|
||||||
HRESULT hr = IDirectInputDevice2_SetEventNotification(Devices[i].Device, Handle);
|
HRESULT hr = Devices[i].Device->SetEventNotification( Handle );
|
||||||
if( FAILED(hr) )
|
if( FAILED(hr) )
|
||||||
LOG->Warn("IDirectInputDevice2_SetEventNotification failed on %i", i);
|
LOG->Warn( "IDirectInputDevice2_SetEventNotification failed on %i", i );
|
||||||
IDirectInputDevice2_Acquire(Devices[i].Device);
|
Devices[i].Device->Acquire();
|
||||||
}
|
}
|
||||||
|
|
||||||
while( !m_bShutdown )
|
while( !m_bShutdown )
|
||||||
@@ -540,16 +540,16 @@ void InputHandler_DInput::InputThreadMain()
|
|||||||
if( !Devices[i].buffered )
|
if( !Devices[i].buffered )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
IDirectInputDevice2_Unacquire(Devices[i].Device);
|
Devices[i].Device->IDirectInputDevice2_Unacquire();
|
||||||
IDirectInputDevice2_SetEventNotification( Devices[i].Device, NULL );
|
Devices[i].Device->SetEventNotification( NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle(Handle);
|
CloseHandle(Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler_DInput::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut)
|
void InputHandler_DInput::GetDevicesAndDescriptions( vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut )
|
||||||
{
|
{
|
||||||
for( unsigned i=0; i < Devices.size(); i++ )
|
for( unsigned i=0; i < Devices.size(); ++i )
|
||||||
{
|
{
|
||||||
vDevicesOut.push_back( Devices[i].dev );
|
vDevicesOut.push_back( Devices[i].dev );
|
||||||
vDescriptionsOut.push_back( Devices[i].JoystickInst.tszProductName );
|
vDescriptionsOut.push_back( Devices[i].JoystickInst.tszProductName );
|
||||||
|
|||||||
Reference in New Issue
Block a user