fix: using own DI instance since we've been horking the one created from display, which when not horked cannot be used, since it does not work with dx3+
fix: changed to use firstime initialization logic like mouse
This commit is contained in:
parent
facd783e4f
commit
eb21d12e86
|
@ -52,8 +52,7 @@ extern HINSTANCE dll_handle;
|
||||||
|
|
||||||
extern HWND hwnd; // Handle to window
|
extern HWND hwnd; // Handle to window
|
||||||
|
|
||||||
extern LPDIRECTINPUT lpdi; // DI instance
|
IDirectInput* cDI; // DI instance
|
||||||
|
|
||||||
IDirectInputDevice2* cDIDevice; // DI Device instance
|
IDirectInputDevice2* cDIDevice; // DI Device instance
|
||||||
DIJOYSTATE2 cJS; // State of Controller
|
DIJOYSTATE2 cJS; // State of Controller
|
||||||
|
|
||||||
|
@ -70,6 +69,7 @@ bool cHasslider; // Temporary slider check
|
||||||
JNIEnv* cEnvironment; // JNIEnvironment copy
|
JNIEnv* cEnvironment; // JNIEnvironment copy
|
||||||
|
|
||||||
bool cCreate_success; // bool used to determine successfull creation
|
bool cCreate_success; // bool used to determine successfull creation
|
||||||
|
bool cFirstTimeInitialization = true; // boolean to determine first time initialization
|
||||||
|
|
||||||
// Cached fields of Controller.java
|
// Cached fields of Controller.java
|
||||||
jclass clsController;
|
jclass clsController;
|
||||||
|
@ -122,7 +122,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_initIDs(JNIEnv * env, jcl
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env, jclass clazz) {
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env, jclass clazz) {
|
||||||
// Create the DirectInput object.
|
// Create the DirectInput object.
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &lpdi, NULL);
|
hr = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &cDI, NULL);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
printf("DirectInputCreate failed\n");
|
printf("DirectInputCreate failed\n");
|
||||||
|
@ -150,6 +150,11 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env,
|
||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check for first time initialization - need to detect capabilities
|
||||||
|
if (cFirstTimeInitialization) {
|
||||||
|
cFirstTimeInitialization = false;
|
||||||
|
|
||||||
|
|
||||||
/* Enumerate capabilities of Controller */
|
/* Enumerate capabilities of Controller */
|
||||||
EnumerateControllerCapabilities();
|
EnumerateControllerCapabilities();
|
||||||
if (!cCreate_success) {
|
if (!cCreate_success) {
|
||||||
|
@ -170,6 +175,12 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env,
|
||||||
|
|
||||||
/* Set capabilities */
|
/* Set capabilities */
|
||||||
SetControllerCapabilities();
|
SetControllerCapabilities();
|
||||||
|
} else {
|
||||||
|
if(cCreate_success) {
|
||||||
|
/* Do setup of Controller */
|
||||||
|
SetupController();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Aquire the Controller */
|
/* Aquire the Controller */
|
||||||
hr = cDIDevice->Acquire();
|
hr = cDIDevice->Acquire();
|
||||||
|
@ -253,7 +264,7 @@ void EnumerateControllerCapabilities() {
|
||||||
*/
|
*/
|
||||||
void EnumerateControllers() {
|
void EnumerateControllers() {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = lpdi->EnumDevices(DIDEVTYPE_JOYSTICK, EnumControllerCallback, 0, DIEDFL_ATTACHEDONLY);
|
hr = cDI->EnumDevices(DIDEVTYPE_JOYSTICK, EnumControllerCallback, 0, DIEDFL_ATTACHEDONLY);
|
||||||
if FAILED(hr) {
|
if FAILED(hr) {
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
printf("EnumDevices failed\n");
|
printf("EnumDevices failed\n");
|
||||||
|
@ -313,7 +324,7 @@ BOOL CALLBACK EnumControllerObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LP
|
||||||
*/
|
*/
|
||||||
void CreateController(LPCDIDEVICEINSTANCE lpddi) {
|
void CreateController(LPCDIDEVICEINSTANCE lpddi) {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = lpdi->CreateDevice(lpddi->guidInstance, (LPDIRECTINPUTDEVICE*) &cDIDevice, NULL);
|
hr = cDI->CreateDevice(lpddi->guidInstance, (LPDIRECTINPUTDEVICE*) &cDIDevice, NULL);
|
||||||
if FAILED(hr) {
|
if FAILED(hr) {
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
printf("CreateDevice failed\n");
|
printf("CreateDevice failed\n");
|
||||||
|
|
Loading…
Reference in New Issue