Replace tabs with spaces
This commit is contained in:
@@ -11,19 +11,19 @@ extern HINSTANCE g_hInst;
|
||||
* Ctor: Connect with DI
|
||||
*/
|
||||
JXInput::JXInput( LPDIRECTINPUTDEVICE8 pJoystick, HWND hWnd ) :
|
||||
mpJoystick( pJoystick ),
|
||||
mSliderCount( 0 ),
|
||||
mPOVCount( 0 ),
|
||||
mButtonCount( 0 )
|
||||
mpJoystick( pJoystick ),
|
||||
mSliderCount( 0 ),
|
||||
mPOVCount( 0 ),
|
||||
mButtonCount( 0 )
|
||||
{
|
||||
initAxisConfig();
|
||||
initButtonsConfig();
|
||||
initDirectionalsConfig();
|
||||
initAxisConfig();
|
||||
initButtonsConfig();
|
||||
initDirectionalsConfig();
|
||||
|
||||
if ( FAILED( InitDirectInput( hWnd ) ) )
|
||||
{
|
||||
FreeDirectInput();
|
||||
}
|
||||
if ( FAILED( InitDirectInput( hWnd ) ) )
|
||||
{
|
||||
FreeDirectInput();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,113 +34,113 @@ JXInput::JXInput( LPDIRECTINPUTDEVICE8 pJoystick, HWND hWnd ) :
|
||||
*/
|
||||
JXInput::~JXInput()
|
||||
{
|
||||
FreeDirectInput();
|
||||
FreeDirectInput();
|
||||
}
|
||||
|
||||
|
||||
void JXInput::update()
|
||||
{
|
||||
UpdateInputState();
|
||||
UpdateInputState();
|
||||
}
|
||||
|
||||
|
||||
TCHAR * const JXInput::getName() const
|
||||
{
|
||||
return (TCHAR*)mdiDevInfo.tszInstanceName;
|
||||
return (TCHAR*)mdiDevInfo.tszInstanceName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int JXInput::getNumberOfAxes() const
|
||||
{
|
||||
return mdiDevCaps.dwAxes;
|
||||
return mdiDevCaps.dwAxes;
|
||||
}
|
||||
|
||||
int JXInput::getNumberOfButtons() const
|
||||
{
|
||||
return mButtonCount;
|
||||
return mButtonCount;
|
||||
}
|
||||
|
||||
int JXInput::getNumberOfDirectionals() const
|
||||
{
|
||||
return mPOVCount;
|
||||
return mPOVCount;
|
||||
}
|
||||
|
||||
|
||||
double JXInput::getAxisValueHelper( LONG val, int idx ) const
|
||||
{
|
||||
const AxisConfig& cfg = mAxisConfig[ idx ];
|
||||
const AxisConfig& cfg = mAxisConfig[ idx ];
|
||||
|
||||
double span = (double)( cfg.mMaxValue - cfg.mMinValue );
|
||||
double ret = (double)(val - cfg.mMinValue) / span;
|
||||
|
||||
if ( TYPE_SLIDER != cfg.mType )
|
||||
return ret*2.0 - 1.0;
|
||||
return ret;
|
||||
double span = (double)( cfg.mMaxValue - cfg.mMinValue );
|
||||
double ret = (double)(val - cfg.mMinValue) / span;
|
||||
|
||||
if ( TYPE_SLIDER != cfg.mType )
|
||||
return ret*2.0 - 1.0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
double JXInput::getX() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.lX, ID_X );
|
||||
return getAxisValueHelper( mJS.lX, ID_X );
|
||||
}
|
||||
double JXInput::getY() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.lY, ID_Y );
|
||||
return getAxisValueHelper( mJS.lY, ID_Y );
|
||||
}
|
||||
double JXInput::getZ() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.lZ, ID_Z );
|
||||
return getAxisValueHelper( mJS.lZ, ID_Z );
|
||||
}
|
||||
double JXInput::getRotX() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.lRx, ID_ROTX );
|
||||
return getAxisValueHelper( mJS.lRx, ID_ROTX );
|
||||
}
|
||||
double JXInput::getRotY() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.lRy, ID_ROTY );
|
||||
return getAxisValueHelper( mJS.lRy, ID_ROTY );
|
||||
}
|
||||
double JXInput::getRotZ() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.lRz, ID_ROTZ );
|
||||
return getAxisValueHelper( mJS.lRz, ID_ROTZ );
|
||||
}
|
||||
double JXInput::getSlider0() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.rglSlider[ 0 ], ID_SLIDER0 );
|
||||
return getAxisValueHelper( mJS.rglSlider[ 0 ], ID_SLIDER0 );
|
||||
}
|
||||
double JXInput::getSlider1() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.rglSlider[ 1 ], ID_SLIDER1 );
|
||||
return getAxisValueHelper( mJS.rglSlider[ 1 ], ID_SLIDER1 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool JXInput::isAxisAvailable( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_AXES );
|
||||
return mAxisConfig[ idx ].mIsAvailable;
|
||||
assert( idx < JXINPUT_MAX_AXES );
|
||||
return mAxisConfig[ idx ].mIsAvailable;
|
||||
}
|
||||
|
||||
TCHAR * const JXInput::getAxisName( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_AXES );
|
||||
return (char*const)mAxisConfig[ idx ].mName;
|
||||
assert( idx < JXINPUT_MAX_AXES );
|
||||
return (char*const)mAxisConfig[ idx ].mName;
|
||||
}
|
||||
|
||||
int JXInput::getAxisType( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_AXES );
|
||||
return mAxisConfig[ idx ].mType;
|
||||
assert( idx < JXINPUT_MAX_AXES );
|
||||
return mAxisConfig[ idx ].mType;
|
||||
}
|
||||
|
||||
double JXInput::getAxisValue( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_AXES );
|
||||
assert( idx < JXINPUT_MAX_AXES );
|
||||
|
||||
// Failsafe if called accidentally
|
||||
if ( ! mAxisConfig[ idx ].mIsAvailable )
|
||||
return 0.0;
|
||||
// Failsafe if called accidentally
|
||||
if ( ! mAxisConfig[ idx ].mIsAvailable )
|
||||
return 0.0;
|
||||
|
||||
return (this->*mAxisConfig[ idx ].mGetValueMethod)();
|
||||
return (this->*mAxisConfig[ idx ].mGetValueMethod)();
|
||||
}
|
||||
|
||||
|
||||
@@ -149,45 +149,45 @@ double JXInput::getAxisValue( int idx ) const
|
||||
|
||||
bool JXInput::isButtonAvailable( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||
return mButtonConfig[ idx ].mIsAvailable;
|
||||
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||
return mButtonConfig[ idx ].mIsAvailable;
|
||||
}
|
||||
|
||||
TCHAR * const JXInput::getButtonName( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||
return (char*const)mButtonConfig[ idx ].mName;
|
||||
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||
return (char*const)mButtonConfig[ idx ].mName;
|
||||
}
|
||||
|
||||
int JXInput::getButtonType( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||
return mButtonConfig[ idx ].mType;
|
||||
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||
return mButtonConfig[ idx ].mType;
|
||||
}
|
||||
|
||||
bool JXInput::isButtonDown( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||
return 0 != mJS.rgbButtons[ idx ] ;
|
||||
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||
return 0 != mJS.rgbButtons[ idx ] ;
|
||||
}
|
||||
|
||||
|
||||
bool JXInput::isDirectionalAvailable( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_DIRECTIONALS );
|
||||
return mDirectionalConfig[ idx ].mIsAvailable;
|
||||
assert( idx < JXINPUT_MAX_DIRECTIONALS );
|
||||
return mDirectionalConfig[ idx ].mIsAvailable;
|
||||
}
|
||||
|
||||
TCHAR * const JXInput::getDirectionalName( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_DIRECTIONALS );
|
||||
return (char*const)mDirectionalConfig[ idx ].mName;
|
||||
assert( idx < JXINPUT_MAX_DIRECTIONALS );
|
||||
return (char*const)mDirectionalConfig[ idx ].mName;
|
||||
}
|
||||
|
||||
int JXInput::getDirection( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_DIRECTIONALS );
|
||||
return mJS.rgdwPOV[ idx ] ;
|
||||
assert( idx < JXINPUT_MAX_DIRECTIONALS );
|
||||
return mJS.rgdwPOV[ idx ] ;
|
||||
}
|
||||
|
||||
|
||||
@@ -196,37 +196,37 @@ int JXInput::getDirection( int idx ) const
|
||||
*/
|
||||
void JXInput::initAxisConfig()
|
||||
{
|
||||
mAxisConfig[ ID_X ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_X ].mType = TYPE_TRANSLATION;
|
||||
mAxisConfig[ ID_X ].mGetValueMethod = &JXInput::getX;
|
||||
mAxisConfig[ ID_X ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_X ].mType = TYPE_TRANSLATION;
|
||||
mAxisConfig[ ID_X ].mGetValueMethod = &JXInput::getX;
|
||||
|
||||
mAxisConfig[ ID_Y ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_Y ].mType = TYPE_TRANSLATION;
|
||||
mAxisConfig[ ID_Y ].mGetValueMethod = &JXInput::getY;
|
||||
mAxisConfig[ ID_Y ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_Y ].mType = TYPE_TRANSLATION;
|
||||
mAxisConfig[ ID_Y ].mGetValueMethod = &JXInput::getY;
|
||||
|
||||
mAxisConfig[ ID_Z ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_Z ].mType = TYPE_TRANSLATION;
|
||||
mAxisConfig[ ID_Z ].mGetValueMethod = &JXInput::getZ;
|
||||
mAxisConfig[ ID_Z ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_Z ].mType = TYPE_TRANSLATION;
|
||||
mAxisConfig[ ID_Z ].mGetValueMethod = &JXInput::getZ;
|
||||
|
||||
mAxisConfig[ ID_ROTX ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_ROTX ].mType = TYPE_ROTATION;
|
||||
mAxisConfig[ ID_ROTX ].mGetValueMethod = &JXInput::getRotX;
|
||||
mAxisConfig[ ID_ROTX ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_ROTX ].mType = TYPE_ROTATION;
|
||||
mAxisConfig[ ID_ROTX ].mGetValueMethod = &JXInput::getRotX;
|
||||
|
||||
mAxisConfig[ ID_ROTY ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_ROTY ].mType = TYPE_ROTATION;
|
||||
mAxisConfig[ ID_ROTY ].mGetValueMethod = &JXInput::getRotY;
|
||||
mAxisConfig[ ID_ROTY ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_ROTY ].mType = TYPE_ROTATION;
|
||||
mAxisConfig[ ID_ROTY ].mGetValueMethod = &JXInput::getRotY;
|
||||
|
||||
mAxisConfig[ ID_ROTZ ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_ROTZ ].mType = TYPE_ROTATION;
|
||||
mAxisConfig[ ID_ROTZ ].mGetValueMethod = &JXInput::getRotZ;
|
||||
|
||||
mAxisConfig[ ID_SLIDER0 ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_SLIDER0 ].mType = TYPE_SLIDER;
|
||||
mAxisConfig[ ID_SLIDER0 ].mGetValueMethod = &JXInput::getSlider0;
|
||||
mAxisConfig[ ID_ROTZ ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_ROTZ ].mType = TYPE_ROTATION;
|
||||
mAxisConfig[ ID_ROTZ ].mGetValueMethod = &JXInput::getRotZ;
|
||||
|
||||
mAxisConfig[ ID_SLIDER0 ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_SLIDER0 ].mType = TYPE_SLIDER;
|
||||
mAxisConfig[ ID_SLIDER0 ].mGetValueMethod = &JXInput::getSlider0;
|
||||
|
||||
mAxisConfig[ ID_SLIDER1 ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_SLIDER1 ].mType = TYPE_SLIDER;
|
||||
mAxisConfig[ ID_SLIDER1 ].mGetValueMethod = &JXInput::getSlider1;
|
||||
mAxisConfig[ ID_SLIDER1 ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_SLIDER1 ].mType = TYPE_SLIDER;
|
||||
mAxisConfig[ ID_SLIDER1 ].mGetValueMethod = &JXInput::getSlider1;
|
||||
}
|
||||
|
||||
|
||||
@@ -235,12 +235,12 @@ void JXInput::initAxisConfig()
|
||||
*/
|
||||
void JXInput::initButtonsConfig()
|
||||
{
|
||||
for ( int i = 0; i < JXINPUT_MAX_BUTTONS; ++i )
|
||||
{
|
||||
mButtonConfig[ i ].mIsAvailable = false;
|
||||
mButtonConfig[ i ].mName[ 0 ] = '\0';
|
||||
mButtonConfig[ i ].mType = TYPE_PUSHBUTTON;
|
||||
}
|
||||
for ( int i = 0; i < JXINPUT_MAX_BUTTONS; ++i )
|
||||
{
|
||||
mButtonConfig[ i ].mIsAvailable = false;
|
||||
mButtonConfig[ i ].mName[ 0 ] = '\0';
|
||||
mButtonConfig[ i ].mType = TYPE_PUSHBUTTON;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -250,11 +250,11 @@ void JXInput::initButtonsConfig()
|
||||
*/
|
||||
void JXInput::initDirectionalsConfig()
|
||||
{
|
||||
for ( int i = 0; i < JXINPUT_MAX_DIRECTIONALS; ++i )
|
||||
{
|
||||
mDirectionalConfig[ i ].mIsAvailable = false;
|
||||
mDirectionalConfig[ i ].mName[ 0 ] = '\0';
|
||||
}
|
||||
for ( int i = 0; i < JXINPUT_MAX_DIRECTIONALS; ++i )
|
||||
{
|
||||
mDirectionalConfig[ i ].mIsAvailable = false;
|
||||
mDirectionalConfig[ i ].mName[ 0 ] = '\0';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -267,46 +267,46 @@ void JXInput::initDirectionalsConfig()
|
||||
BOOL CALLBACK JXInput::EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||
VOID* pContext )
|
||||
{
|
||||
JXInput* pThis = (JXInput*)pContext;
|
||||
JXInput* pThis = (JXInput*)pContext;
|
||||
|
||||
AxisConfig* pAxCfg = NULL;
|
||||
AxisConfig* pAxCfg = NULL;
|
||||
|
||||
// Set the UI to reflect what objects the joystick supports
|
||||
// Code derived from M$ samples, really sucks, eh?
|
||||
// Code derived from M$ samples, really sucks, eh?
|
||||
if (pdidoi->guidType == GUID_XAxis)
|
||||
{
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_X ];
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_X ];
|
||||
}
|
||||
if (pdidoi->guidType == GUID_YAxis)
|
||||
{
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_Y ];
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_Y ];
|
||||
}
|
||||
if (pdidoi->guidType == GUID_ZAxis)
|
||||
{
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_Z ];
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_Z ];
|
||||
}
|
||||
if (pdidoi->guidType == GUID_RxAxis)
|
||||
{
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_ROTX ];
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_ROTX ];
|
||||
}
|
||||
if (pdidoi->guidType == GUID_RyAxis)
|
||||
{
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_ROTY ];
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_ROTY ];
|
||||
}
|
||||
if (pdidoi->guidType == GUID_RzAxis)
|
||||
{
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_ROTZ ];
|
||||
}
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_ROTZ ];
|
||||
}
|
||||
if (pdidoi->guidType == GUID_Slider)
|
||||
{
|
||||
switch( pThis->mSliderCount++ )
|
||||
{
|
||||
case 0 :
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_SLIDER0 ];
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_SLIDER0 ];
|
||||
break;
|
||||
|
||||
case 1 :
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_SLIDER1 ];
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_SLIDER1 ];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -316,25 +316,25 @@ BOOL CALLBACK JXInput::EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||
return DIENUM_CONTINUE;
|
||||
|
||||
|
||||
//
|
||||
// Perform config.
|
||||
//
|
||||
//
|
||||
// Perform config.
|
||||
//
|
||||
|
||||
DIPROPRANGE diprg;
|
||||
diprg.diph.dwSize = sizeof(DIPROPRANGE);
|
||||
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
diprg.diph.dwHow = DIPH_BYID;
|
||||
diprg.diph.dwHow = DIPH_BYID;
|
||||
diprg.diph.dwObj = pdidoi->dwType; // Specify the enumerated axis
|
||||
|
||||
// Get the range for the axis
|
||||
if( FAILED( pThis->mpJoystick->GetProperty( DIPROP_RANGE, &diprg.diph ) ) )
|
||||
return DIENUM_CONTINUE;
|
||||
|
||||
pAxCfg->mMinValue = diprg.lMin;
|
||||
pAxCfg->mMaxValue = diprg.lMax;
|
||||
pAxCfg->mMinValue = diprg.lMin;
|
||||
pAxCfg->mMaxValue = diprg.lMax;
|
||||
|
||||
strcpy( (char*)pAxCfg->mName, (char*)pdidoi->tszName );
|
||||
pAxCfg->mIsAvailable = true;
|
||||
strcpy( (char*)pAxCfg->mName, (char*)pdidoi->tszName );
|
||||
pAxCfg->mIsAvailable = true;
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
@@ -348,39 +348,39 @@ BOOL CALLBACK JXInput::EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||
BOOL CALLBACK JXInput::EnumButtonsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||
VOID* pContext )
|
||||
{
|
||||
JXInput* pThis = (JXInput*)pContext;
|
||||
JXInput* pThis = (JXInput*)pContext;
|
||||
|
||||
//
|
||||
// if the maximum number of buttons is already registered,
|
||||
// issue a warning and stop enumeration.
|
||||
//
|
||||
if( JXINPUT_MAX_BUTTONS == pThis->mButtonCount )
|
||||
{
|
||||
OutputDebugString( "Max. number of buttons exceeded!" );
|
||||
return DIENUM_STOP;
|
||||
}
|
||||
//
|
||||
// if the maximum number of buttons is already registered,
|
||||
// issue a warning and stop enumeration.
|
||||
//
|
||||
if( JXINPUT_MAX_BUTTONS == pThis->mButtonCount )
|
||||
{
|
||||
OutputDebugString( "Max. number of buttons exceeded!" );
|
||||
return DIENUM_STOP;
|
||||
}
|
||||
|
||||
|
||||
ButtonConfig* pBtCfg = NULL;
|
||||
ButtonConfig* pBtCfg = NULL;
|
||||
|
||||
if ( pdidoi->guidType == GUID_Button )
|
||||
{
|
||||
assert( JXINPUT_MAX_BUTTONS > pThis->mButtonCount );
|
||||
pBtCfg = & pThis->mButtonConfig[ pThis->mButtonCount++ ];
|
||||
}
|
||||
assert( JXINPUT_MAX_BUTTONS > pThis->mButtonCount );
|
||||
pBtCfg = & pThis->mButtonConfig[ pThis->mButtonCount++ ];
|
||||
}
|
||||
|
||||
|
||||
// fail-safe
|
||||
if( NULL == pBtCfg ) // e.g. unknown stuff
|
||||
return DIENUM_CONTINUE;
|
||||
assert( NULL != pBtCfg );
|
||||
assert( NULL != pBtCfg );
|
||||
|
||||
//
|
||||
// Perform config.
|
||||
//
|
||||
//
|
||||
// Perform config.
|
||||
//
|
||||
|
||||
strcpy( (char*)pBtCfg->mName, (char*)pdidoi->tszName );
|
||||
pBtCfg->mIsAvailable = true;
|
||||
strcpy( (char*)pBtCfg->mName, (char*)pdidoi->tszName );
|
||||
pBtCfg->mIsAvailable = true;
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
@@ -393,38 +393,38 @@ BOOL CALLBACK JXInput::EnumButtonsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi
|
||||
BOOL CALLBACK JXInput::EnumPOVsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||
VOID* pContext )
|
||||
{
|
||||
JXInput* pThis = (JXInput*)pContext;
|
||||
JXInput* pThis = (JXInput*)pContext;
|
||||
|
||||
//
|
||||
// if the maximum number of buttons is already registered,
|
||||
// issue a warning and stop enumeration.
|
||||
//
|
||||
if( JXINPUT_MAX_DIRECTIONALS == pThis->mPOVCount )
|
||||
{
|
||||
OutputDebugString( "Max. number of POVs exceeded!" );
|
||||
return DIENUM_STOP;
|
||||
}
|
||||
//
|
||||
// if the maximum number of buttons is already registered,
|
||||
// issue a warning and stop enumeration.
|
||||
//
|
||||
if( JXINPUT_MAX_DIRECTIONALS == pThis->mPOVCount )
|
||||
{
|
||||
OutputDebugString( "Max. number of POVs exceeded!" );
|
||||
return DIENUM_STOP;
|
||||
}
|
||||
|
||||
DirectionalConfig* pDirCfg = NULL;
|
||||
DirectionalConfig* pDirCfg = NULL;
|
||||
|
||||
|
||||
if (pdidoi->guidType == GUID_POV)
|
||||
{
|
||||
assert( JXINPUT_MAX_DIRECTIONALS > pThis->mPOVCount );
|
||||
pDirCfg = & pThis->mDirectionalConfig[ pThis->mPOVCount++ ];
|
||||
assert( JXINPUT_MAX_DIRECTIONALS > pThis->mPOVCount );
|
||||
pDirCfg = & pThis->mDirectionalConfig[ pThis->mPOVCount++ ];
|
||||
}
|
||||
|
||||
// fail-safe
|
||||
if( NULL == pDirCfg ) // e.g. unknown stuff
|
||||
return DIENUM_CONTINUE;
|
||||
assert( NULL != pDirCfg );
|
||||
assert( NULL != pDirCfg );
|
||||
|
||||
//
|
||||
// Perform config.
|
||||
//
|
||||
//
|
||||
// Perform config.
|
||||
//
|
||||
|
||||
strcpy( (char*)pDirCfg->mName, (char*)pdidoi->tszName );
|
||||
pDirCfg->mIsAvailable = true;
|
||||
strcpy( (char*)pDirCfg->mName, (char*)pdidoi->tszName );
|
||||
pDirCfg->mIsAvailable = true;
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
@@ -436,13 +436,13 @@ BOOL CALLBACK JXInput::EnumPOVsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||
// Desc: Callback function for enumerating the effects of a joystick
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL CALLBACK JXInput::EnumEffectsCallback( const DIEFFECTINFO* pdidoi,
|
||||
VOID* pContext )
|
||||
VOID* pContext )
|
||||
{
|
||||
//JXInput* pThis = (JXInput*)pContext;
|
||||
//JXInput* pThis = (JXInput*)pContext;
|
||||
|
||||
//
|
||||
// Work on that!!
|
||||
//
|
||||
//
|
||||
// Work on that!!
|
||||
//
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
@@ -463,12 +463,12 @@ HRESULT JXInput::InitDirectInput( HWND hWnd )
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Ask the device for some useful information.
|
||||
//
|
||||
mdiDevInfo.dwSize = sizeof( DIDEVICEINSTANCE );
|
||||
hr = mpJoystick->GetDeviceInfo( &mdiDevInfo );
|
||||
|
||||
//
|
||||
// Ask the device for some useful information.
|
||||
//
|
||||
mdiDevInfo.dwSize = sizeof( DIDEVICEINSTANCE );
|
||||
hr = mpJoystick->GetDeviceInfo( &mdiDevInfo );
|
||||
if( FAILED(hr) )
|
||||
return hr;
|
||||
|
||||
@@ -484,10 +484,10 @@ HRESULT JXInput::InitDirectInput( HWND hWnd )
|
||||
// Set the cooperative level to let DInput know how this device should
|
||||
// interact with the system and with other DInput applications.
|
||||
// hr = g_pJoystick->SetCooperativeLevel( hDlg, DISCL_EXCLUSIVE|DISCL_FOREGROUND );
|
||||
DWORD mode = ( NULL == hWnd ? DISCL_NONEXCLUSIVE|DISCL_BACKGROUND : DISCL_EXCLUSIVE|DISCL_BACKGROUND );
|
||||
hr = mpJoystick->SetCooperativeLevel( hWnd, mode );
|
||||
if( FAILED(hr) )
|
||||
return hr;
|
||||
DWORD mode = ( NULL == hWnd ? DISCL_NONEXCLUSIVE|DISCL_BACKGROUND : DISCL_EXCLUSIVE|DISCL_BACKGROUND );
|
||||
hr = mpJoystick->SetCooperativeLevel( hWnd, mode );
|
||||
if( FAILED(hr) )
|
||||
return hr;
|
||||
|
||||
// Determine how many axis the joystick has (so we don't error out setting
|
||||
// properties for unavailable axis)
|
||||
@@ -500,14 +500,14 @@ HRESULT JXInput::InitDirectInput( HWND hWnd )
|
||||
// Enumerate the axes of the joyctick and set the range of each axis. Note:
|
||||
// we could just use the defaults, but we're just trying to show an example
|
||||
// of enumerating device objects (axes, buttons, etc.).
|
||||
mpJoystick->EnumObjects( EnumAxesCallback, (VOID*)this, DIDFT_AXIS );
|
||||
mpJoystick->EnumObjects( EnumButtonsCallback, (VOID*)this, DIDFT_BUTTON );
|
||||
mpJoystick->EnumObjects( EnumPOVsCallback, (VOID*)this, DIDFT_POV );
|
||||
mpJoystick->EnumObjects( EnumAxesCallback, (VOID*)this, DIDFT_AXIS );
|
||||
mpJoystick->EnumObjects( EnumButtonsCallback, (VOID*)this, DIDFT_BUTTON );
|
||||
mpJoystick->EnumObjects( EnumPOVsCallback, (VOID*)this, DIDFT_POV );
|
||||
|
||||
mpJoystick->EnumEffects( EnumEffectsCallback, (VOID*)this, DIEFT_ALL );
|
||||
mpJoystick->EnumEffects( EnumEffectsCallback, (VOID*)this, DIEFT_ALL );
|
||||
|
||||
// For FF sticks, switch on autocenter as long as we do not use real FF
|
||||
SwitchAutoCenter( true );
|
||||
// For FF sticks, switch on autocenter as long as we do not use real FF
|
||||
SwitchAutoCenter( true );
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
@@ -527,27 +527,27 @@ HRESULT JXInput::UpdateInputState()
|
||||
if( mpJoystick )
|
||||
{
|
||||
|
||||
// Poll the device to read the current state
|
||||
hr = mpJoystick->Poll();
|
||||
if( FAILED(hr) )
|
||||
{
|
||||
// DInput is telling us that the input stream has been
|
||||
// interrupted. We aren't tracking any state between polls, so
|
||||
// we don't have any special reset that needs to be done. We
|
||||
// just re-acquire and try again.
|
||||
hr = mpJoystick->Acquire();
|
||||
while( hr == DIERR_INPUTLOST )
|
||||
hr = mpJoystick->Acquire();
|
||||
// Poll the device to read the current state
|
||||
hr = mpJoystick->Poll();
|
||||
if( FAILED(hr) )
|
||||
{
|
||||
// DInput is telling us that the input stream has been
|
||||
// interrupted. We aren't tracking any state between polls, so
|
||||
// we don't have any special reset that needs to be done. We
|
||||
// just re-acquire and try again.
|
||||
hr = mpJoystick->Acquire();
|
||||
while( hr == DIERR_INPUTLOST )
|
||||
hr = mpJoystick->Acquire();
|
||||
|
||||
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This
|
||||
// may occur when the app is minimized or in the process of
|
||||
// switching, so just try again later
|
||||
return S_OK;
|
||||
}
|
||||
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This
|
||||
// may occur when the app is minimized or in the process of
|
||||
// switching, so just try again later
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// Get the input's device state
|
||||
if( FAILED( hr = mpJoystick->GetDeviceState( sizeof(DIJOYSTATE2), &mJS ) ) )
|
||||
return hr; // The device should have been acquired during the Poll()
|
||||
// Get the input's device state
|
||||
if( FAILED( hr = mpJoystick->GetDeviceState( sizeof(DIJOYSTATE2), &mJS ) ) )
|
||||
return hr; // The device should have been acquired during the Poll()
|
||||
|
||||
}
|
||||
|
||||
@@ -570,8 +570,8 @@ HRESULT JXInput::FreeDirectInput()
|
||||
// the app tried to exit while the device is still acquired.
|
||||
mpJoystick->Unacquire();
|
||||
|
||||
mpJoystick->Release();
|
||||
mpJoystick = NULL;
|
||||
mpJoystick->Release();
|
||||
mpJoystick = NULL;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
@@ -583,14 +583,14 @@ HRESULT JXInput::SwitchAutoCenter( bool onoff )
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
DIPROPDWORD DIPropAutoCenter;
|
||||
DIPROPDWORD DIPropAutoCenter;
|
||||
|
||||
DIPropAutoCenter.diph.dwSize = sizeof(DIPropAutoCenter);
|
||||
DIPropAutoCenter.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
DIPropAutoCenter.diph.dwObj = 0;
|
||||
DIPropAutoCenter.diph.dwHow = DIPH_DEVICE;
|
||||
DIPropAutoCenter.dwData = ( onoff ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF );
|
||||
DIPropAutoCenter.diph.dwSize = sizeof(DIPropAutoCenter);
|
||||
DIPropAutoCenter.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
DIPropAutoCenter.diph.dwObj = 0;
|
||||
DIPropAutoCenter.diph.dwHow = DIPH_DEVICE;
|
||||
DIPropAutoCenter.dwData = ( onoff ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF );
|
||||
|
||||
hr = mpJoystick->SetProperty( DIPROP_AUTOCENTER, &DIPropAutoCenter.diph );
|
||||
return hr;
|
||||
hr = mpJoystick->SetProperty( DIPROP_AUTOCENTER, &DIPropAutoCenter.diph );
|
||||
return hr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user