|
From: Elias N. <eli...@us...> - 2003-12-15 11:49:21
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/win32 In directory sc8-pr-cvs1:/tmp/cvs-serv8597/src/native/win32 Modified Files: org_lwjgl_Display.cpp org_lwjgl_Sys.cpp org_lwjgl_input_Controller.cpp org_lwjgl_input_Keyboard.cpp org_lwjgl_input_Mouse.cpp org_lwjgl_opengl_Window.cpp Log Message: Replaced debug libraries with runtime debug condition Index: org_lwjgl_Display.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/win32/org_lwjgl_Display.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_Display.cpp,v retrieving revision 1.55 retrieving revision 1.56 diff -u -d -r1.55 -r1.56 --- org_lwjgl_Display.cpp 10 Nov 2003 01:41:57 -0000 1.55 +++ org_lwjgl_Display.cpp 15 Dec 2003 11:49:17 -0000 1.56 @@ -45,8 +45,8 @@ #define WINDOWCLASSNAME "LWJGLWINDOW" -jobjectArray GetAvailableDisplayModesEx(JNIEnv * env); -jobjectArray GetAvailableDisplayModes(JNIEnv * env); +static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env); +static jobjectArray GetAvailableDisplayModes(JNIEnv * env); bool modeSet = false; // Whether we've done a display mode change WORD* originalGamma = new WORD[256 * 3]; // Original gamma settings WORD* currentGamma = new WORD[256 * 3]; // Current gamma settings @@ -62,9 +62,7 @@ { jobjectArray result = GetAvailableDisplayModesEx(env); if (result == NULL) { -#ifdef _DEBUG - printf("Extended display mode selection failed, using fallback\n"); -#endif + printfDebug("Extended display mode selection failed, using fallback\n"); result = GetAvailableDisplayModes(env); } return result; @@ -73,7 +71,7 @@ /** * Choose displaymodes using extended codepath (multiple displaydevices) */ -jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) { +static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) { typedef BOOL (WINAPI * EnumDisplayDevicesAPROC)(IN LPCSTR lpDevice, IN DWORD iDevNum, OUT PDISPLAY_DEVICEA lpDisplayDevice, IN DWORD dwFlags); typedef BOOL (WINAPI * EnumDisplaySettingsExAPROC)(IN LPCSTR lpszDeviceName, IN DWORD iModeNum, OUT LPDEVMODEA lpDevMode, IN DWORD dwFlags); EnumDisplayDevicesAPROC EnumDisplayDevicesA; @@ -81,9 +79,7 @@ HMODULE lib_handle = LoadLibrary("user32.dll"); if (lib_handle == NULL) { -#ifdef _DEBUG - printf("Could not load user32.dll\n"); -#endif + printfDebug("Could not load user32.dll\n"); return NULL; } EnumDisplayDevicesA = (EnumDisplayDevicesAPROC)GetProcAddress(lib_handle, "EnumDisplayDevicesA"); @@ -105,25 +101,18 @@ DevMode.dmSize = sizeof(DEVMODE); DisplayDevice.cb = sizeof(DISPLAY_DEVICE); - //enumerate all displays, and all of their displaymodes + //enumerate all displays, and all of their displaymodes while(EnumDisplayDevicesA(NULL, i++, &DisplayDevice, 0) != 0) { -#ifdef _DEBUG - printf("Querying %s device\n", DisplayDevice.DeviceString); -#endif + printfDebug("Querying %s device\n", DisplayDevice.DeviceString); j = 0; while(EnumDisplaySettingsExA((const char *) DisplayDevice.DeviceName, j++, &DevMode, 0) != 0) { -//#ifdef _DEBUG -// printf("Checking setting #%d\n", j); -//#endif if (DevMode.dmBitsPerPel > 8) { AvailableModes++; } } } -#ifdef _DEBUG - printf("Found %d displaymodes\n", AvailableModes); -#endif + printfDebug("Found %d displaymodes\n", AvailableModes); // now that we have the count create the classes, and add 'em all - we'll remove dups in Java // Allocate an array of DisplayModes big enough @@ -154,7 +143,7 @@ /** * Choose displaymodes using standard codepath (single displaydevice) */ -jobjectArray GetAvailableDisplayModes(JNIEnv * env) { +static jobjectArray GetAvailableDisplayModes(JNIEnv * env) { int i = 0, j = 0, n = 0; int AvailableModes = 0; @@ -171,9 +160,7 @@ } } -#ifdef _DEBUG - printf("Found %d displaymodes\n", AvailableModes); -#endif + printfDebug("Found %d displaymodes\n", AvailableModes); // now that we have the count create the classes, and add 'em all - we'll remove dups in Java // Allocate an array of DisplayModes big enough @@ -243,16 +230,12 @@ if (cdsret != DISP_CHANGE_SUCCESSFUL) { // Failed: so let's check to see if it's a wierd dual screen display -#ifdef _DEBUG - printf("Failed to set display mode... assuming dual monitors\n"); -#endif + printfDebug("Failed to set display mode... assuming dual monitors\n"); devmode.dmPelsWidth = width * 2; cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN); if (cdsret != DISP_CHANGE_SUCCESSFUL) { -#ifdef _DEBUG - printf("Failed to set display mode using dual monitors\n"); -#endif + printfDebug("Failed to set display mode using dual monitors\n"); throwException(env, "Failed to set display mode."); return; } @@ -295,9 +278,7 @@ HDC screenDC = GetDC(NULL); try { if (!SetDeviceGammaRamp(screenDC, originalGamma)) { - #ifdef _DEBUG - printf("Could not reset device gamma\n"); - #endif + printfDebug("Could not reset device gamma\n"); } } catch (...) { printf("Exception occurred in SetDeviceGammaRamp\n"); @@ -317,14 +298,12 @@ /* * Temporarily reset display settings. This is called when the window is minimized. */ -void tempResetDisplayMode() { +static void tempResetDisplayMode() { // Return device gamma to normal HDC screenDC = GetDC(NULL); try { if (!SetDeviceGammaRamp(screenDC, originalGamma)) { - #ifdef _DEBUG - printf("Could not reset device gamma\n"); - #endif + printfDebug("Could not reset device gamma\n"); } } catch (...) { printf("Exception occurred in SetDeviceGammaRamp\n"); @@ -332,9 +311,7 @@ ReleaseDC(NULL, screenDC); if (modeSet) { -#ifdef _DEBUG - printf("Attempting to temporarily reset the display mode\n"); -#endif + printfDebug("Attempting to temporarily reset the display mode\n"); modeSet = false; // Under Win32, all we have to do is: ChangeDisplaySettings(NULL, 0); @@ -344,14 +321,12 @@ /* * Put display settings back to what they were when the window is maximized. */ -void tempRestoreDisplayMode() { +static void tempRestoreDisplayMode() { // Restore gamma HDC screenDC = GetDC(NULL); try { if (!SetDeviceGammaRamp(screenDC, currentGamma)) { - #ifdef _DEBUG - printf("Could not restore device gamma\n"); - #endif + printfDebug("Could not restore device gamma\n"); } } catch (...) { printf("Exception occurred in SetDeviceGammaRamp\n"); @@ -359,18 +334,13 @@ ReleaseDC(NULL, screenDC); if (!modeSet) { - -#ifdef _DEBUG - printf("Attempting to restore the display mode\n"); -#endif + printfDebug("Attempting to restore the display mode\n"); modeSet = true; LONG cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN); -#ifdef _DEBUG if (cdsret != DISP_CHANGE_SUCCESSFUL) { - printf("Failed to restore display mode\n"); + printfDebug("Failed to restore display mode\n"); } -#endif } } @@ -445,9 +415,7 @@ // Get the default gamma ramp try { if (GetDeviceGammaRamp(screenDC, originalGamma) == FALSE) { - #ifdef _DEBUG - printf("Failed to get initial device gamma\n"); - #endif + printfDebug("Failed to get initial device gamma\n"); } } catch (...) { printf("Exception occurred in GetDeviceGammaRamp\n"); @@ -457,34 +425,32 @@ } -char * getDriver() { - #define MY_BUFSIZE 256 +static char * getDriver() { + #define MY_BUFSIZE 256 - HKEY hKey; - static TCHAR szAdapterKey[MY_BUFSIZE], szDriverValue[MY_BUFSIZE]; - DWORD dwBufLen = MY_BUFSIZE; - LONG lRet; + HKEY hKey; + static TCHAR szAdapterKey[MY_BUFSIZE], szDriverValue[MY_BUFSIZE]; + DWORD dwBufLen = MY_BUFSIZE; + LONG lRet; - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, - TEXT("HARDWARE\\DeviceMap\\Video"), - 0, - KEY_QUERY_VALUE, - &hKey) != ERROR_SUCCESS) return NULL; + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, + TEXT("HARDWARE\\DeviceMap\\Video"), + 0, + KEY_QUERY_VALUE, + &hKey) != ERROR_SUCCESS) return NULL; - lRet = RegQueryValueEx(hKey, - TEXT("\\Device\\Video0"), - NULL, - NULL, - (LPBYTE)szAdapterKey, - &dwBufLen); + lRet = RegQueryValueEx(hKey, + TEXT("\\Device\\Video0"), + NULL, + NULL, + (LPBYTE)szAdapterKey, + &dwBufLen); - RegCloseKey(hKey); + RegCloseKey(hKey); - if(lRet != ERROR_SUCCESS) return NULL; + if(lRet != ERROR_SUCCESS) return NULL; -#ifdef _DEBUG - printf("Adapter key: %s\n", szAdapterKey); -#endif + printfDebug("Adapter key: %s\n", szAdapterKey); // szAdapterKey now contains something like \Registry\Machine\System\CurrentControlSet\Control\Video\{B70DBD2A-90C4-41CF-A58E-F3BA69F1A6BC}\0000 // We'll check for the first chunk: @@ -493,9 +459,6 @@ TCHAR szDriverKey[MY_BUFSIZE]; strcpy(szDriverKey, &szAdapterKey[18]); -//#ifdef _DEBUG -// printf("Driver key: %s\n", szDriverKey); -//#endif if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(szDriverKey), @@ -557,27 +520,17 @@ } strcat(driverDLL, driver); strcat(driverDLL, ".dll"); -//#ifdef _DEBUG -// printf("Driver dll = %s\n", driverDLL); -//#endif DWORD var = 0; DWORD dwInfoSize = GetFileVersionInfoSize(driverDLL, &var); LPVOID lpInfoBuff = new unsigned char[dwInfoSize]; BOOL bRetval = GetFileVersionInfo(driverDLL, NULL, dwInfoSize, lpInfoBuff); if (bRetval == 0) { -//#ifdef _DEBUG -// printf("GetFileVersionInfo failed\n"); -//#endif } else { VS_FIXEDFILEINFO * fxdFileInfo; UINT uiLen = 0; bRetval = VerQueryValue(lpInfoBuff, TEXT("\\"), (void **) &fxdFileInfo, &uiLen); - if (bRetval == 0) { -//#ifdef _DEBUG -// printf("VerQueryValue failed\n"); -//#endif - } else { + if (bRetval != 0) { TCHAR version[256]; TCHAR ms[10], ls[10]; sprintf(ms, "%d.%d\0", fxdFileInfo->dwProductVersionMS >> 16, fxdFileInfo->dwProductVersionMS & 0xFFFF); @@ -593,12 +546,4 @@ return ret; } - - - - - - - - Index: org_lwjgl_Sys.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/win32/org_lwjgl_Sys.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_Sys.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- org_lwjgl_Sys.cpp 28 Oct 2003 19:25:50 -0000 1.17 +++ org_lwjgl_Sys.cpp 15 Dec 2003 11:49:17 -0000 1.18 @@ -41,6 +41,7 @@ #include <windows.h> #include "org_lwjgl_Sys.h" +#include "common_tools.h" // Handle to the application's window extern HWND hwnd; @@ -60,6 +61,10 @@ return hires_timer_freq; } +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setDebugLevel(JNIEnv *env, jclass clazz, jint debug_level) { + setDebugLevel(debug_level); +} + /* * Class: org_lwjgl_Sys * Method: getTime @@ -115,9 +120,7 @@ } if (!SetPriorityClass(me, win32priority)) { -#ifdef _DEBUG - printf("Failed to set priority class.\n"); -#endif + printfDebug("Failed to set priority class.\n"); } } @@ -134,9 +137,7 @@ const char * cTitleBarText = env->GetStringUTFChars(title, ©); MessageBox(hwnd, eMessageText, cTitleBarText, MB_OK | MB_TOPMOST); -#ifdef _DEBUG - printf("*** Alert ***%s\n%s\n", cTitleBarText, eMessageText); -#endif + printfDebug("*** Alert ***%s\n%s\n", cTitleBarText, eMessageText); env->ReleaseStringUTFChars(message, eMessageText); env->ReleaseStringUTFChars(title, cTitleBarText); @@ -170,33 +171,31 @@ strncat(command, urlString, 200); // Prevent buffer overflow env->ReleaseStringUTFChars(url, urlString); - STARTUPINFO si; - PROCESS_INFORMATION pi; + STARTUPINFO si; + PROCESS_INFORMATION pi; - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory( &pi, sizeof(pi) ); - // Start the child process. - if( !CreateProcess( NULL, // No module name (use command line). - command, // Command line. - NULL, // Process handle not inheritable. - NULL, // Thread handle not inheritable. - FALSE, // Set handle inheritance to FALSE. - 0, // No creation flags. - NULL, // Use parent's environment block. - NULL, // Use parent's starting directory. - &si, // Pointer to STARTUPINFO structure. - &pi ) // Pointer to PROCESS_INFORMATION structure. - ) - { -#ifdef _DEBUG - printf("Failed to open URL %s\n", urlString); -#endif - } + // Start the child process. + if( !CreateProcess( NULL, // No module name (use command line). + command, // Command line. + NULL, // Process handle not inheritable. + NULL, // Thread handle not inheritable. + FALSE, // Set handle inheritance to FALSE. + 0, // No creation flags. + NULL, // Use parent's environment block. + NULL, // Use parent's starting directory. + &si, // Pointer to STARTUPINFO structure. + &pi ) // Pointer to PROCESS_INFORMATION structure. + ) + { + printfDebug("Failed to open URL %s\n", urlString); + } - // Close process and thread handles. - CloseHandle( pi.hProcess ); - CloseHandle( pi.hThread ); + // Close process and thread handles. + CloseHandle( pi.hProcess ); + CloseHandle( pi.hThread ); } Index: org_lwjgl_input_Controller.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/win32/org_lwjgl_input_Controller.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_input_Controller.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- org_lwjgl_input_Controller.cpp 11 Oct 2003 16:29:40 -0000 1.15 +++ org_lwjgl_input_Controller.cpp 15 Dec 2003 11:49:17 -0000 1.16 @@ -7,15 +7,15 @@ * met: * * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * * * Neither the name of 'Light Weight Java Game Library' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -42,33 +42,33 @@ #define WIN32_LEAN_AND_MEAN #include "org_lwjgl_input_Controller.h" #include <windows.h> -#undef DIRECTINPUT_VERSION +#undef DIRECTINPUT_VERSION #define DIRECTINPUT_VERSION 0x0500 #include <dinput.h> #include "Window.h" #include "common_tools.h" -#define CONTROLLER_AXISMAX 1000 // Maxmimum range to which we'll gauge the swing -#define CONTROLLER_AXISMIN -1000 // Minimum range to which we'll gauge the swing +#define CONTROLLER_AXISMAX 1000 // Maxmimum range to which we'll gauge the swing +#define CONTROLLER_AXISMIN -1000 // Minimum range to which we'll gauge the swing extern HINSTANCE dll_handle; extern HWND hwnd; -static IDirectInput* cDI; // DI instance -static IDirectInputDevice2* cDIDevice; // DI Device instance -static DIJOYSTATE2 cJS; // State of Controller +static IDirectInput* cDI; // DI instance +static IDirectInputDevice2* cDIDevice; // DI Device instance +static DIJOYSTATE2 cJS; // State of Controller -static int cButtoncount = 0; // Temporary buttoncount -static bool cHasx; // Temporary xaxis check -static bool cHasrx; // Temporary rotational xaxis check -static bool cHasy; // Temporary yaxis check -static bool cHasry; // Temporary rotational yaxis check -static bool cHasz; // Temporary zaxis check -static bool cHasrz; // Temporary rotational zaxis check -static bool cHaspov; // Temporary pov check -static bool cHasslider; // Temporary slider check +static int cButtoncount = 0; // Temporary buttoncount +static bool cHasx; // Temporary xaxis check +static bool cHasrx; // Temporary rotational xaxis check +static bool cHasy; // Temporary yaxis check +static bool cHasry; // Temporary rotational yaxis check +static bool cHasz; // Temporary zaxis check +static bool cHasrz; // Temporary rotational zaxis check +static bool cHaspov; // Temporary pov check +static bool cHasslider; // Temporary slider check -static bool cCreate_success; // bool used to determine successfull creation +static bool cCreate_success; // bool used to determine successfull creation static bool cFirstTimeInitialization = true; // boolean to determine first time initialization // Cached fields of Controller.java @@ -108,470 +108,431 @@ * Initializes any field ids */ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_initIDs(JNIEnv * env, jclass clazz) { - /* Cache fields in Controller */ - CacheControllerFields(env, clazz); + /* Cache fields in Controller */ + CacheControllerFields(env, clazz); } /** * Called when the Controller instance is to be created */ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env, jclass clazz) { - // Create the DirectInput object. - HRESULT hr; - hr = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &cDI, NULL); - if (FAILED(hr)) { - #if _DEBUG - printf("DirectInputCreate failed\n"); - #endif - ShutdownController(); - return; - } - - /* Find all Controllers */ - EnumerateControllers(); - if (!cCreate_success) { - throwException(env, "Failed to enumerate."); - ShutdownController(); - return; - } + // Create the DirectInput object. + HRESULT hr; + hr = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &cDI, NULL); + if (FAILED(hr)) { + printfDebug("DirectInputCreate failed\n"); + ShutdownController(); + return; + } - /* check that we got at least 1 controller */ - if (cDIDevice == NULL) { - throwException(env, "No devices found."); - ShutdownController(); - return; - } + /* Find all Controllers */ + EnumerateControllers(); + if (!cCreate_success) { + throwException(env, "Failed to enumerate."); + ShutdownController(); + return; + } - //check for first time initialization - need to detect capabilities - if (cFirstTimeInitialization) { - cFirstTimeInitialization = false; + /* check that we got at least 1 controller */ + if (cDIDevice == NULL) { + throwException(env, "No devices found."); + ShutdownController(); + return; + } + //check for first time initialization - need to detect capabilities + if (cFirstTimeInitialization) { + cFirstTimeInitialization = false; - /* Enumerate capabilities of Controller */ - EnumerateControllerCapabilities(); - if (!cCreate_success) { - throwException(env, "Falied to enumerate capabilities."); - ShutdownController(); - return; - } + /* Enumerate capabilities of Controller */ + EnumerateControllerCapabilities(); + if (!cCreate_success) { + throwException(env, "Falied to enumerate capabilities."); + ShutdownController(); + return; + } - /* Do setup of Controller */ - SetupController(); + /* Do setup of Controller */ + SetupController(); - /* Initialize any fields on the Controller */ - InitializeControllerFields(env, clazz); + /* Initialize any fields on the Controller */ + InitializeControllerFields(env, clazz); - /* Set capabilities */ - SetControllerCapabilities(env, clazz); - } else { - if(cCreate_success) { - /* Do setup of Controller */ - SetupController(); - - /* Initialize any fields on the Controller */ - InitializeControllerFields(env, clazz); - } - } + /* Set capabilities */ + SetControllerCapabilities(env, clazz); + } else { + if(cCreate_success) { + /* Do setup of Controller */ + SetupController(); + + /* Initialize any fields on the Controller */ + InitializeControllerFields(env, clazz); + } + } - /* Aquire the Controller */ - hr = cDIDevice->Acquire(); - if(FAILED(hr)) { - throwException(env, "Acquire failed"); - ShutdownController(); - return; - } + /* Aquire the Controller */ + hr = cDIDevice->Acquire(); + if(FAILED(hr)) { + throwException(env, "Acquire failed"); + ShutdownController(); + return; + } } /* - * Class: org_lwjgl_input_Controller - * Method: nDestroy + * Class: org_lwjgl_input_Controller + * Method: nDestroy * Signature: ()V */ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nDestroy(JNIEnv *env, jclass clazz) { - ShutdownController(); + ShutdownController(); } /* - * Class: org_lwjgl_input_Controller - * Method: nPoll + * Class: org_lwjgl_input_Controller + * Method: nPoll * Signature: ()V */ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nPoll(JNIEnv * env, jclass clazz) { - HRESULT hRes; + HRESULT hRes; - // poll the Controller to read the current state - hRes = cDIDevice->Poll(); - if (FAILED(hRes)) { -#if _DEBUG - printf("Poll fail\n"); -#endif + // poll the Controller to read the current state + hRes = cDIDevice->Poll(); + if (FAILED(hRes)) { + printfDebug("Poll fail\n"); - //check if we need to reaquire - if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) { - cDIDevice->Acquire(); -#if _DEBUG - printf("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success); -#endif - } - return; - } + //check if we need to reaquire + if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) { + cDIDevice->Acquire(); + printfDebug("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success); + } + return; + } - UpdateControllerFields(env, clazz); + UpdateControllerFields(env, clazz); } /** * Shutdown DI */ static void ShutdownController() { - // release device - if (cDIDevice != NULL) { - cDIDevice->Unacquire(); - cDIDevice->Release(); - cDIDevice = NULL; - } + // release device + if (cDIDevice != NULL) { + cDIDevice->Unacquire(); + cDIDevice->Release(); + cDIDevice = NULL; + } } /** * Enumerates the capabilities of the Controller attached to the system */ static void EnumerateControllerCapabilities() { - HRESULT hr; - hr = cDIDevice->EnumObjects(EnumControllerObjectsCallback, NULL, DIDFT_ALL); - if FAILED(hr) { -#if _DEBUG - printf("EnumObjects failed\n"); -#endif - cCreate_success = false; - return; - } - cCreate_success = true; + HRESULT hr; + hr = cDIDevice->EnumObjects(EnumControllerObjectsCallback, NULL, DIDFT_ALL); + if FAILED(hr) { + printfDebug("EnumObjects failed\n"); + cCreate_success = false; + return; + } + cCreate_success = true; } /** * Enumerates the Controllers attached to the system */ static void EnumerateControllers() { - HRESULT hr; - hr = cDI->EnumDevices(DIDEVTYPE_JOYSTICK, EnumControllerCallback, 0, DIEDFL_ATTACHEDONLY); - if FAILED(hr) { -#if _DEBUG - printf("EnumDevices failed\n"); -#endif - cCreate_success = false; - return; - } - cCreate_success = true; + HRESULT hr; + hr = cDI->EnumDevices(DIDEVTYPE_JOYSTICK, EnumControllerCallback, 0, DIEDFL_ATTACHEDONLY); + if FAILED(hr) { + printfDebug("EnumDevices failed\n"); + cCreate_success = false; + return; + } + cCreate_success = true; } /** * Callback from EnumDevices. Called for each Controller attached to the system */ BOOL CALLBACK EnumControllerCallback(LPCDIDEVICEINSTANCE pdinst, LPVOID pvRef) { - /* Add the Controller */ - CreateController(pdinst); + /* Add the Controller */ + CreateController(pdinst); - /* just stop after 1st Controller */ - return DIENUM_STOP; + /* just stop after 1st Controller */ + return DIENUM_STOP; } /** * Callback from EnumObjects. Called for each "object" on the Controller. */ BOOL CALLBACK EnumControllerObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) { -#if _DEBUG - printf("found %s\n", lpddoi->tszName); -#endif - if(lpddoi->guidType == GUID_Button) { - cButtoncount++; - } else if(lpddoi->guidType == GUID_XAxis) { - cHasx = true; - } else if(lpddoi->guidType == GUID_YAxis) { - cHasy = true; - } else if(lpddoi->guidType == GUID_ZAxis){ - cHasz = true; - } else if (lpddoi->guidType == GUID_POV){ - cHaspov = true; - } else if (lpddoi->guidType == GUID_Slider){ - cHasslider = true; - } else if (lpddoi->guidType == GUID_RxAxis) { - cHasrx = true; - } else if (lpddoi->guidType == GUID_RyAxis) { - cHasry = true; - } else if (lpddoi->guidType == GUID_RzAxis) { - cHasrz = true; -#if _DEBUG - } else { - printf("Unhandled object found: %s\n", lpddoi->tszName); -#endif - } - return DIENUM_CONTINUE; + printfDebug("found %s\n", lpddoi->tszName); + if(lpddoi->guidType == GUID_Button) { + cButtoncount++; + } else if(lpddoi->guidType == GUID_XAxis) { + cHasx = true; + } else if(lpddoi->guidType == GUID_YAxis) { + cHasy = true; + } else if(lpddoi->guidType == GUID_ZAxis){ + cHasz = true; + } else if (lpddoi->guidType == GUID_POV){ + cHaspov = true; + } else if (lpddoi->guidType == GUID_Slider){ + cHasslider = true; + } else if (lpddoi->guidType == GUID_RxAxis) { + cHasrx = true; + } else if (lpddoi->guidType == GUID_RyAxis) { + cHasry = true; + } else if (lpddoi->guidType == GUID_RzAxis) { + cHasrz = true; + } else { + printfDebug("Unhandled object found: %s\n", lpddoi->tszName); + } + return DIENUM_CONTINUE; } /** * Creates the specified device as a Controller */ static void CreateController(LPCDIDEVICEINSTANCE lpddi) { - HRESULT hr; - hr = cDI->CreateDevice(lpddi->guidInstance, (LPDIRECTINPUTDEVICE*) &cDIDevice, NULL); - if FAILED(hr) { -#if _DEBUG - printf("CreateDevice failed\n"); -#endif - cCreate_success = false; - return; - } - cCreate_success = true; + HRESULT hr; + hr = cDI->CreateDevice(lpddi->guidInstance, (LPDIRECTINPUTDEVICE*) &cDIDevice, NULL); + if FAILED(hr) { + printfDebug("CreateDevice failed\n"); + cCreate_success = false; + return; + } + cCreate_success = true; } /** * Sets up the Controller properties */ static void SetupController() { - // set Controller data format - if(cDIDevice->SetDataFormat(&c_dfDIJoystick2) != DI_OK) { -#if _DEBUG - printf("SetDataFormat failed\n"); -#endif - cCreate_success = false; - return; - } + // set Controller data format + if(cDIDevice->SetDataFormat(&c_dfDIJoystick2) != DI_OK) { + printfDebug("SetDataFormat failed\n"); + cCreate_success = false; + return; + } - // set the cooperative level - if(cDIDevice->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) { -#if _DEBUG - printf("SetCooperativeLevel failed\n"); -#endif - cCreate_success = false; - return; - } - - // set range to (-1000 ... +1000) - // This lets us test against 0 to see which way the stick is pointed. - DIPROPRANGE diprg; - diprg.diph.dwSize = sizeof(diprg); - diprg.diph.dwHeaderSize = sizeof(diprg.diph); - diprg.diph.dwHow = DIPH_BYOFFSET; - diprg.lMin = CONTROLLER_AXISMIN; - diprg.lMax = CONTROLLER_AXISMAX; + // set the cooperative level + if(cDIDevice->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) { + printfDebug("SetCooperativeLevel failed\n"); + cCreate_success = false; + return; + } + + // set range to (-1000 ... +1000) + // This lets us test against 0 to see which way the stick is pointed. + DIPROPRANGE diprg; + diprg.diph.dwSize = sizeof(diprg); + diprg.diph.dwHeaderSize = sizeof(diprg.diph); + diprg.diph.dwHow = DIPH_BYOFFSET; + diprg.lMin = CONTROLLER_AXISMIN; + diprg.lMax = CONTROLLER_AXISMAX; - // set X-axis - if(cHasx) { - diprg.diph.dwObj = DIJOFS_X; - if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { -#if _DEBUG - printf("SetProperty(DIJOFS_X) failed\n"); -#endif - cCreate_success = false; - return; - } - } + // set X-axis + if(cHasx) { + diprg.diph.dwObj = DIJOFS_X; + if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { + printfDebug("SetProperty(DIJOFS_X) failed\n"); + cCreate_success = false; + return; + } + } - // set RX-axis - if(cHasrx) { - diprg.diph.dwObj = DIJOFS_RX; - if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { -#if _DEBUG - printf("SetProperty(DIJOFS_RX) failed\n"); -#endif - cCreate_success = false; - return; - } - } + // set RX-axis + if(cHasrx) { + diprg.diph.dwObj = DIJOFS_RX; + if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { + printfDebug("SetProperty(DIJOFS_RX) failed\n"); + cCreate_success = false; + return; + } + } - // set Y-axis - if(cHasy) { - diprg.diph.dwObj = DIJOFS_Y; - if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { -#if _DEBUG - printf("SetProperty(DIJOFS_Y) failed\n"); -#endif - cCreate_success = false; - return; - } - } + // set Y-axis + if(cHasy) { + diprg.diph.dwObj = DIJOFS_Y; + if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { + printfDebug("SetProperty(DIJOFS_Y) failed\n"); + cCreate_success = false; + return; + } + } - // set RY-axis - if(cHasry) { - diprg.diph.dwObj = DIJOFS_RY; - if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { -#if _DEBUG - pr... [truncated message content] |