Make the callbacks static members, so they can access private members.
Make m_pJoystick and GetDirectInput private. Don't bail out on Update if the joystick fails, since we still have more devices. Just log--handle error conditions on our own. Reduce Windows types in the interface; eventually it'll need to be clean. Remove unused Get*Device functions.
This commit is contained in:
+23
-25
@@ -305,7 +305,7 @@ char DeviceInput::ToChar() const
|
|||||||
// Desc: Called once for each enumerated joystick. If we find one, create a
|
// Desc: Called once for each enumerated joystick. If we find one, create a
|
||||||
// device interface on it so we can play with it.
|
// device interface on it so we can play with it.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,
|
BOOL CALLBACK RageInput::EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,
|
||||||
VOID* pContext )
|
VOID* pContext )
|
||||||
{
|
{
|
||||||
RageInput* pInput = (RageInput*)pContext;
|
RageInput* pInput = (RageInput*)pContext;
|
||||||
@@ -334,7 +334,7 @@ BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,
|
|||||||
// Name: EnumAxesCallMenuBack( const PlayerNumber p )
|
// Name: EnumAxesCallMenuBack( const PlayerNumber p )
|
||||||
// Desc: Callback function for enumerating the axes on a joystick
|
// Desc: Callback function for enumerating the axes on a joystick
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
BOOL CALLBACK EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
BOOL CALLBACK RageInput::EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||||
VOID* pContext )
|
VOID* pContext )
|
||||||
{
|
{
|
||||||
LPDIRECTINPUTDEVICE8 pJoystick = (LPDIRECTINPUTDEVICE8)pContext;
|
LPDIRECTINPUTDEVICE8 pJoystick = (LPDIRECTINPUTDEVICE8)pContext;
|
||||||
@@ -656,7 +656,7 @@ HRESULT RageInput::UpdatePump()
|
|||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT RageInput::Update()
|
void RageInput::Update()
|
||||||
{
|
{
|
||||||
// macros for reading DI state structures
|
// macros for reading DI state structures
|
||||||
#define IS_PRESSED(b) (b & 0x80)
|
#define IS_PRESSED(b) (b & 0x80)
|
||||||
@@ -698,35 +698,33 @@ HRESULT RageInput::Update()
|
|||||||
for( BYTE i=0; i<4; i++ ) // foreach joystick
|
for( BYTE i=0; i<4; i++ ) // foreach joystick
|
||||||
{
|
{
|
||||||
// read joystick states
|
// read joystick states
|
||||||
if ( m_pJoystick[i] )
|
if ( !m_pJoystick[i] )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Poll the device to read the current state
|
||||||
|
hr = m_pJoystick[i]->Poll();
|
||||||
|
if( FAILED(hr) )
|
||||||
{
|
{
|
||||||
// Poll the device to read the current state
|
// DInput is telling us that the input stream has been
|
||||||
hr = m_pJoystick[i]->Poll();
|
// interrupted. We aren't tracking any state between polls, so
|
||||||
if( FAILED(hr) )
|
// we don't have any special reset that needs to be done. We
|
||||||
{
|
// just re-acquire and try again.
|
||||||
// DInput is telling us that the input stream has been
|
hr = m_pJoystick[i]->Acquire();
|
||||||
// interrupted. We aren't tracking any state between polls, so
|
while( hr == DIERR_INPUTLOST )
|
||||||
// we don't have any special reset that needs to be done. We
|
|
||||||
// just re-acquire and try again.
|
|
||||||
hr = m_pJoystick[i]->Acquire();
|
hr = m_pJoystick[i]->Acquire();
|
||||||
while( hr == DIERR_INPUTLOST )
|
|
||||||
hr = m_pJoystick[i]->Acquire();
|
|
||||||
|
|
||||||
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This
|
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This
|
||||||
// may occur when the app is minimized or in the process of
|
// may occur when the app is minimized or in the process of
|
||||||
// switching, so just try again later
|
// switching, so just try again later
|
||||||
return E_FAIL;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
// Get the input's device state
|
|
||||||
if( FAILED( hr = m_pJoystick[i]->GetDeviceState( sizeof(DIJOYSTATE2), &m_joyState[i] ) ) )
|
|
||||||
return hr; // The device should have been acquired during the Poll()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the input's device state
|
||||||
|
if( FAILED( hr = m_pJoystick[i]->GetDeviceState( sizeof(DIJOYSTATE2), &m_joyState[i] ) ) )
|
||||||
|
LOG->Trace(hr, "Failed to read joystick %i\n", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdatePump();
|
UpdatePump();
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+10
-12
@@ -86,13 +86,9 @@ class RageInput
|
|||||||
LPDIRECTINPUTDEVICE8 m_pKeyboard;
|
LPDIRECTINPUTDEVICE8 m_pKeyboard;
|
||||||
// Mouse Device
|
// Mouse Device
|
||||||
LPDIRECTINPUTDEVICE8 m_pMouse;
|
LPDIRECTINPUTDEVICE8 m_pMouse;
|
||||||
public:
|
|
||||||
// hack: make them public to allow the callbacks access to the pointers
|
|
||||||
// Joystick Devices
|
// Joystick Devices
|
||||||
LPDIRECTINPUTDEVICE8 m_pJoystick[NUM_JOYSTICKS];
|
LPDIRECTINPUTDEVICE8 m_pJoystick[NUM_JOYSTICKS];
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Arrays for Keyboard Data
|
// Arrays for Keyboard Data
|
||||||
byte m_keys[NUM_KEYBOARD_BUTTONS];
|
byte m_keys[NUM_KEYBOARD_BUTTONS];
|
||||||
byte m_oldKeys[NUM_KEYBOARD_BUTTONS];
|
byte m_oldKeys[NUM_KEYBOARD_BUTTONS];
|
||||||
@@ -127,10 +123,18 @@ private:
|
|||||||
INT m_RelPosition_x;
|
INT m_RelPosition_x;
|
||||||
INT m_RelPosition_y;
|
INT m_RelPosition_y;
|
||||||
|
|
||||||
|
static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,
|
||||||
|
VOID* pContext );
|
||||||
|
|
||||||
|
static BOOL CALLBACK EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||||
|
VOID* pContext );
|
||||||
|
|
||||||
HRESULT UpdateMouse();
|
HRESULT UpdateMouse();
|
||||||
HRESULT UpdateKeyboard();
|
HRESULT UpdateKeyboard();
|
||||||
HRESULT UpdatePump();
|
HRESULT UpdatePump();
|
||||||
|
|
||||||
|
LPDIRECTINPUT8 GetDirectInput() { return m_pDI; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RageInput(HWND hWnd);
|
RageInput(HWND hWnd);
|
||||||
~RageInput();
|
~RageInput();
|
||||||
@@ -140,18 +144,12 @@ public:
|
|||||||
// Release all DirectInput Resources
|
// Release all DirectInput Resources
|
||||||
void Release();
|
void Release();
|
||||||
// Get our Devices State
|
// Get our Devices State
|
||||||
HRESULT Update();
|
void Update();
|
||||||
bool IsBeingPressed( DeviceInput di );
|
bool IsBeingPressed( DeviceInput di );
|
||||||
bool WasBeingPressed( DeviceInput di );
|
bool WasBeingPressed( DeviceInput di );
|
||||||
|
|
||||||
LPDIRECTINPUT8 GetDirectInput() { return m_pDI; }
|
|
||||||
LPDIRECTINPUTDEVICE8 GetMouseDevice() { return m_pMouse; }
|
|
||||||
LPDIRECTINPUTDEVICE8 GetKeyboardDevice() { return m_pKeyboard; }
|
|
||||||
LPDIRECTINPUTDEVICE8 GetJoystickDevice( int i ) { return m_pJoystick[i]; }
|
|
||||||
|
|
||||||
// DIMOUSESTATE2 GetMouseState() { return dimMouseState; }
|
// DIMOUSESTATE2 GetMouseState() { return dimMouseState; }
|
||||||
VOID GetAbsPosition( DWORD &x, DWORD &y ) { x = m_AbsPosition_x; y = m_AbsPosition_y; }
|
void GetAbsPosition( DWORD &x, DWORD &y ) const { x = m_AbsPosition_x; y = m_AbsPosition_y; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace USB {
|
namespace USB {
|
||||||
|
|||||||
Reference in New Issue
Block a user