Change to how NRage is dynamically linking XInput, rather than loading it every time functions such as GetXInputControllerKeys is called. Do it on initiate of controllers. Still not the best way to handle it.

Need to rethink the way NRage handles the different API's rather than just tacking it on the side
This commit is contained in:
Emmet Young 2015-02-22 21:11:20 +11:00
parent e51ec31e65
commit 6b1a88d3a4
2 changed files with 11 additions and 31 deletions

View File

@ -155,17 +155,6 @@ void AxisDeadzone( SHORT &AxisValue, long lDeadZoneValue, float fDeadZoneRelati
void GetXInputControllerKeys( const int indexController, LPDWORD Keys ) void GetXInputControllerKeys( const int indexController, LPDWORD Keys )
{ {
HMODULE hInput = LoadLibrary("Xinput1_4.dll");
if (hInput == NULL)
{
hInput = LoadLibrary("Xinput9_1_0.dll");
}
if (hInput == NULL)
{
return;
}
DWORD(WINAPI * fnXInputGetState) (DWORD dwUserIndex, XINPUT_STATE* pState) = NULL;
if (fnXInputGetState == NULL) if (fnXInputGetState == NULL)
{ {
return; return;
@ -302,6 +291,11 @@ void DefaultXInputControllerKeys( LPXCONTROLLER gController)
void VibrateXInputController( DWORD nController, int LeftMotorVal, int RightMotorVal ) void VibrateXInputController( DWORD nController, int LeftMotorVal, int RightMotorVal )
{ {
if (fnXInputSetState == NULL)
{
return;
}
XINPUT_VIBRATION vibration; XINPUT_VIBRATION vibration;
ZeroMemory( &vibration, sizeof( XINPUT_VIBRATION ) ); ZeroMemory( &vibration, sizeof( XINPUT_VIBRATION ) );
@ -309,23 +303,6 @@ void VibrateXInputController( DWORD nController, int LeftMotorVal, int RightMoto
vibration.wLeftMotorSpeed = LeftMotorVal; vibration.wLeftMotorSpeed = LeftMotorVal;
vibration.wRightMotorSpeed = RightMotorVal; vibration.wRightMotorSpeed = RightMotorVal;
HMODULE hInput = LoadLibrary("Xinput1_4.dll");
if (hInput == NULL)
{
hInput = LoadLibrary("Xinput9_1_0.dll");
}
if (hInput == NULL)
{
return;
}
DWORD (WINAPI * fnXInputSetState) ( DWORD dwUserIndex, XINPUT_VIBRATION* pVibration ) = NULL;
fnXInputSetState = (DWORD(WINAPI *) (DWORD, XINPUT_VIBRATION*))GetProcAddress(hInput, "XInputSetState");
if (fnXInputSetState == NULL)
{
return;
}
fnXInputSetState(nController, &vibration); fnXInputSetState(nController, &vibration);
} }
@ -341,9 +318,9 @@ bool InitiateXInputController( LPXCONTROLLER gController, int nControl )
return false; return false;
} }
DWORD(WINAPI * fnXInputGetState) (DWORD dwUserIndex, XINPUT_STATE* pState) = NULL; fnXInputSetState = (DWORD(WINAPI *) (DWORD, XINPUT_VIBRATION*))GetProcAddress(hInput, "XInputSetState");
fnXInputGetState = (DWORD(WINAPI *) (DWORD, XINPUT_STATE*))GetProcAddress(hInput, "XInputGetState"); fnXInputGetState = (DWORD(WINAPI *) (DWORD, XINPUT_STATE*))GetProcAddress(hInput, "XInputGetState");
if (fnXInputGetState == NULL) if (fnXInputGetState == NULL || fnXInputSetState == NULL)
{ {
return false; return false;
} }

View File

@ -114,6 +114,9 @@ void VibrateXInputController( DWORD nController, int LeftMotorVal = 65535, int R
// Initialize nControl XInput enabled controller // Initialize nControl XInput enabled controller
bool InitiateXInputController( LPXCONTROLLER gController, int nControl ); bool InitiateXInputController( LPXCONTROLLER gController, int nControl );
static DWORD(WINAPI * fnXInputGetState) (DWORD dwUserIndex, XINPUT_STATE* pState) = NULL;
static DWORD(WINAPI * fnXInputSetState) (DWORD dwUserIndex, XINPUT_VIBRATION* pVibration) = NULL;
// XController dialog // XController dialog
#define XC_DPAD 1 #define XC_DPAD 1