|
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 - printf("SetProperty(DIJOFS_RY) failed\n"); -#endif - cCreate_success = false; - return; - } - } + // set RY-axis + if(cHasry) { + diprg.diph.dwObj = DIJOFS_RY; + if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { + printfDebug("SetProperty(DIJOFS_RY) failed\n"); + cCreate_success = false; + return; + } + } - // set Z-axis - if(cHasz) { - diprg.diph.dwObj = DIJOFS_Z; - if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { -#if _DEBUG - printf("SetProperty(DIJOFS_Z) failed\n"); -#endif - cCreate_success = false; - return; - } - } + // set Z-axis + if(cHasz) { + diprg.diph.dwObj = DIJOFS_Z; + if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { + printfDebug("SetProperty(DIJOFS_Z) failed\n"); + cCreate_success = false; + return; + } + } - // set RZ-axis - if(cHasrz) { - diprg.diph.dwObj = DIJOFS_RZ; - if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { -#if _DEBUG - printf("SetProperty(DIJOFS_RZ) failed\n"); -#endif - cCreate_success = false; - return; - } - } + // set RZ-axis + if(cHasrz) { + diprg.diph.dwObj = DIJOFS_RZ; + if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { + printfDebug("SetProperty(DIJOFS_RZ) failed\n"); + cCreate_success = false; + return; + } + } - // - // Lastly slider - // using z axis since we're running dx 5 - // - if(cHasslider) { - diprg.diph.dwObj = DIJOFS_Z; - if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { -#if _DEBUG - printf("SetProperty(DIJOFS_Z(SLIDER)) failed\n"); -#endif - cCreate_success = false; - return; - } - } - cCreate_success = true; + // + // Lastly slider + // using z axis since we're running dx 5 + // + if(cHasslider) { + diprg.diph.dwObj = DIJOFS_Z; + if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { + printfDebug("SetProperty(DIJOFS_Z(SLIDER)) failed\n"); + cCreate_success = false; + return; + } + } + cCreate_success = true; } /** * Sets the fields on the Controller */ static void InitializeControllerFields(JNIEnv *env, jclass clsController) { - //create buttons array - jbooleanArray cButtonsArray = env->NewBooleanArray(cButtoncount); - - //set buttons array - env->SetStaticObjectField(clsController, fidCButtons, cButtonsArray); + //create buttons array + jbooleanArray cButtonsArray = env->NewBooleanArray(cButtoncount); + + //set buttons array + env->SetStaticObjectField(clsController, fidCButtons, cButtonsArray); } /** * Updates the fields on the Controller */ static void UpdateControllerFields(JNIEnv *env, jclass clsController) { - HRESULT hRes; + HRESULT hRes; - // get data from the Controller - hRes = cDIDevice->GetDeviceState(sizeof(DIJOYSTATE2), &cJS); + // get data from the Controller + hRes = cDIDevice->GetDeviceState(sizeof(DIJOYSTATE2), &cJS); - if (hRes != DI_OK) { - // did the read fail because we lost input for some reason? - // if so, then attempt to reacquire. - if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) { - cDIDevice->Acquire(); -#if _DEBUG - printf("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success); -#endif - } -#if _DEBUG - printf("Error getting controller state: %d\n", hRes); -#endif - return; - } + if (hRes != DI_OK) { + // did the read fail because we lost input for some reason? + // if so, then attempt to reacquire. + if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) { + cDIDevice->Acquire(); + printfDebug("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success); + } + printfDebug("Error getting controller state: %d\n", hRes); + return; + } - //axis's - if(cHasx) { - env->SetStaticIntField(clsController, fidCX, cJS.lX); - } + //axis's + if(cHasx) { + env->SetStaticIntField(clsController, fidCX, cJS.lX); + } - if(cHasy) { - env->SetStaticIntField(clsController, fidCY, cJS.lY); - } + if(cHasy) { + env->SetStaticIntField(clsController, fidCY, cJS.lY); + } - if(cHasz) { - env->SetStaticIntField(clsController, fidCZ, cJS.lZ); - } + if(cHasz) { + env->SetStaticIntField(clsController, fidCZ, cJS.lZ); + } - //rotational axis - if(cHasrx) { - env->SetStaticIntField(clsController, fidCRX, cJS.lRx); - } + //rotational axis + if(cHasrx) { + env->SetStaticIntField(clsController, fidCRX, cJS.lRx); + } - if(cHasry) { - env->SetStaticIntField(clsController, fidCRY, cJS.lRy); - } + if(cHasry) { + env->SetStaticIntField(clsController, fidCRY, cJS.lRy); + } - if(cHasrz) { - env->SetStaticIntField(clsController, fidCRZ, cJS.lRz); - } + if(cHasrz) { + env->SetStaticIntField(clsController, fidCRZ, cJS.lRz); + } - //buttons - for (int i = 0; i < cButtoncount; i++) { - if (cJS.rgbButtons[i] != 0) { - cJS.rgbButtons[i] = 1; - } else { - cJS.rgbButtons[i] = 0; - } - } - jbyteArray buttonsArray = (jbyteArray) env->GetStaticObjectField(clsController, fidCButtons); - env->SetByteArrayRegion(buttonsArray, 0, cButtoncount, (jbyte *)cJS.rgbButtons); + //buttons + for (int i = 0; i < cButtoncount; i++) { + if (cJS.rgbButtons[i] != 0) { + cJS.rgbButtons[i] = 1; + } else { + cJS.rgbButtons[i] = 0; + } + } + jbyteArray buttonsArray = (jbyteArray) env->GetStaticObjectField(clsController, fidCButtons); + env->SetByteArrayRegion(buttonsArray, 0, cButtoncount, (jbyte *)cJS.rgbButtons); - //pov - if(cHaspov) { - env->SetStaticIntField(clsController, fidCPOV, cJS.rgdwPOV[0]); - } + //pov + if(cHaspov) { + env->SetStaticIntField(clsController, fidCPOV, cJS.rgdwPOV[0]); + } - //slider - if(cHasslider) { - env->SetStaticIntField(clsController, fidCSlider, cJS.lZ); - } + //slider + if(cHasslider) { + env->SetStaticIntField(clsController, fidCSlider, cJS.lZ); + } } /** * Sets the capabilities of the Controller */ static void SetControllerCapabilities(JNIEnv *env, jclass clsController) { - //set buttoncount - env->SetStaticIntField(clsController, fidCButtonCount, cButtoncount); + //set buttoncount + env->SetStaticIntField(clsController, fidCButtonCount, cButtoncount); - //set axis - env->SetStaticBooleanField(clsController, fidCHasXAxis, cHasx); - env->SetStaticBooleanField(clsController, fidCHasYAxis, cHasy); - env->SetStaticBooleanField(clsController, fidCHasZAxis, cHasz); + //set axis + env->SetStaticBooleanField(clsController, fidCHasXAxis, cHasx); + env->SetStaticBooleanField(clsController, fidCHasYAxis, cHasy); + env->SetStaticBooleanField(clsController, fidCHasZAxis, cHasz); - //set rotational axis - env->SetStaticBooleanField(clsController, fidCHasRXAxis, cHasrx); - env->SetStaticBooleanField(clsController, fidCHasRYAxis, cHasry); - env->SetStaticBooleanField(clsController, fidCHasRZAxis, cHasrz); + //set rotational axis + env->SetStaticBooleanField(clsController, fidCHasRXAxis, cHasrx); + env->SetStaticBooleanField(clsController, fidCHasRYAxis, cHasry); + env->SetStaticBooleanField(clsController, fidCHasRZAxis, cHasrz); - //set pov - env->SetStaticBooleanField(clsController, fidCHasPOV, cHaspov); + //set pov + env->SetStaticBooleanField(clsController, fidCHasPOV, cHaspov); - //set slider - env->SetStaticBooleanField(clsController, fidCHasSlider, cHasslider); + //set slider + env->SetStaticBooleanField(clsController, fidCHasSlider, cHasslider); } /** * Caches the field ids for quicker access */ static void CacheControllerFields(JNIEnv *env, jclass clsController) { - fidCButtonCount = env->GetStaticFieldID(clsController, "buttonCount", "I"); - fidCHasXAxis = env->GetStaticFieldID(clsController, "hasXAxis", "Z"); - fidCHasRXAxis = env->GetStaticFieldID(clsController, "hasRXAxis", "Z"); - fidCHasYAxis = env->GetStaticFieldID(clsController, "hasYAxis", "Z"); - fidCHasRYAxis = env->GetStaticFieldID(clsController, "hasRYAxis", "Z"); - fidCHasZAxis = env->GetStaticFieldID(clsController, "hasZAxis", "Z"); - fidCHasRZAxis = env->GetStaticFieldID(clsController, "hasRZAxis", "Z"); - fidCHasPOV = env->GetStaticFieldID(clsController, "hasPOV", "Z"); - fidCHasSlider = env->GetStaticFieldID(clsController, "hasSlider", "Z"); - fidCButtons = env->GetStaticFieldID(clsController, "buttons", "[Z"); - fidCX = env->GetStaticFieldID(clsController, "x", "I"); - fidCRX = env->GetStaticFieldID(clsController, "rx", "I"); - fidCY = env->GetStaticFieldID(clsController, "y", "I"); - fidCRY = env->GetStaticFieldID(clsController, "ry", "I"); - fidCZ = env->GetStaticFieldID(clsController, "z", "I"); - fidCRZ = env->GetStaticFieldID(clsController, "rz", "I"); - fidCPOV = env->GetStaticFieldID(clsController, "pov", "I"); - fidCSlider = env->GetStaticFieldID(clsController, "slider", "I"); + fidCButtonCount = env->GetStaticFieldID(clsController, "buttonCount", "I"); + fidCHasXAxis = env->GetStaticFieldID(clsController, "hasXAxis", "Z"); + fidCHasRXAxis = env->GetStaticFieldID(clsController, "hasRXAxis", "Z"); + fidCHasYAxis = env->GetStaticFieldID(clsController, "hasYAxis", "Z"); + fidCHasRYAxis = env->GetStaticFieldID(clsController, "hasRYAxis", "Z"); + fidCHasZAxis = env->GetStaticFieldID(clsController, "hasZAxis", "Z"); + fidCHasRZAxis = env->GetStaticFieldID(clsController, "hasRZAxis", "Z"); + fidCHasPOV = env->GetStaticFieldID(clsController, "hasPOV", "Z"); + fidCHasSlider = env->GetStaticFieldID(clsController, "hasSlider", "Z"); + fidCButtons = env->GetStaticFieldID(clsController, "buttons", "[Z"); + fidCX = env->GetStaticFieldID(clsController, "x", "I"); + fidCRX = env->GetStaticFieldID(clsController, "rx", "I"); + fidCY = env->GetStaticFieldID(clsController, "y", "I"); + fidCRY = env->GetStaticFieldID(clsController, "ry", "I"); + fidCZ = env->GetStaticFieldID(clsController, "z", "I"); + fidCRZ = env->GetStaticFieldID(clsController, "rz", "I"); + fidCPOV = env->GetStaticFieldID(clsController, "pov", "I"); + fidCSlider = env->GetStaticFieldID(clsController, "slider", "I"); } Index: org_lwjgl_input_Keyboard.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/win32/org_lwjgl_input_Keyboard.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_input_Keyboard.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- org_lwjgl_input_Keyboard.cpp 11 Oct 2003 16:29:40 -0000 1.25 +++ org_lwjgl_input_Keyboard.cpp 15 Dec 2003 11:49:17 -0000 1.26 @@ -110,9 +110,7 @@ HRESULT ret = lpdiKeyboard->Acquire(); if(FAILED(ret)) { -#if _DEBUG - printf("Failed to acquire keyboard\n"); -#endif + printfDebug("Failed to acquire keyboard\n"); } } @@ -200,11 +198,6 @@ if (ret == DI_OK) { unsigned char * buf = readBuffer; -//#ifdef _DEBUG -// if (bufsize > 0) { -// printf("Got %d keyboard events.\n", bufsize); -// } -//#endif for (unsigned int i = 0; i < bufsize; i ++) { num_events++; *buf++ = (unsigned char) rgdod[i].dwOfs; @@ -252,33 +245,19 @@ } } } else if (ret == DI_BUFFEROVERFLOW) { -#ifdef _DEBUG - printf("Keyboard buffer overflowed\n"); -#endif + printfDebug("Keyboard buffer overflowed\n"); } else if (ret == DIERR_INPUTLOST) { -#ifdef _DEBUG - printf("Input lost\n"); -#endif + printfDebug("Input lost\n"); } else if (ret == DIERR_NOTACQUIRED) { -#ifdef _DEBUG - printf("not acquired\n"); -#endif + printfDebug("not acquired\n"); } else if (ret == DIERR_INVALIDPARAM) { -#ifdef _DEBUG - printf("invalid parameter\n"); -#endif + printfDebug("invalid parameter\n"); } else if (ret == DIERR_NOTBUFFERED) { -#ifdef _DEBUG - printf("not buffered\n"); -#endif + printfDebug("not buffered\n"); } else if (ret == DIERR_NOTINITIALIZED) { -#ifdef _DEBUG - printf("not inited\n"); -#endif + printfDebug("not inited\n"); } else { -#ifdef _DEBUG - printf("unknown keyboard error\n"); -#endif + printfDebug("unknown keyboard error\n"); } return num_events; } Index: org_lwjgl_input_Mouse.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/win32/org_lwjgl_input_Mouse.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_input_Mouse.cpp,v retrieving revision 1.39 retrieving revision 1.40 diff -u -d -r1.39 -r1.40 --- org_lwjgl_input_Mouse.cpp 23 Nov 2003 12:52:08 -0000 1.39 +++ org_lwjgl_input_Mouse.cpp 15 Dec 2003 11:49:17 -0000 1.40 @@ -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 @@ -41,7 +41,7 @@ #define WIN32_LEAN_AND_MEAN #include "org_lwjgl_input_Mouse.h" #include <windows.h> -#undef DIRECTINPUT_VERSION +#undef DIRECTINPUT_VERSION #define DIRECTINPUT_VERSION 0x0300 #include "Window.h" #include "common_tools.h" @@ -49,11 +49,11 @@ static BYTE readBuffer[EVENT_BUFFER_SIZE]; -static LPDIRECTINPUTDEVICE mDIDevice; // DI Device instance -static int mButtoncount = 0; // Temporary buttoncount -static bool mHaswheel; // Temporary wheel check +static LPDIRECTINPUTDEVICE mDIDevice; // DI Device instance +static int mButtoncount = 0; // Temporary buttoncount +static bool mHaswheel; // Temporary wheel check -static bool mCreate_success; // bool used to determine successfull creation +static bool mCreate_success; // bool used to determine successfull creation static bool mFirstTimeInitialization = true; // boolean to determine first time initialization // Cached fields of Mouse.java @@ -90,8 +90,8 @@ * Initializes any field ids */ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_initIDs(JNIEnv * env, jclass clazz) { - /* Cache fields in Mouse */ - CacheMouseFields(env, clazz); + /* Cache fields in Mouse */ + CacheMouseFields(env, clazz); } JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Mouse_nHasWheel(JNIEnv *, jclass) { @@ -129,15 +129,13 @@ } else { if(mCreate_success) { /* Do setup of Mouse */ - SetupMouse(); + SetupMouse(); } } /* Aquire the Mouse */ hr = mDIDevice->Acquire(); if(FAILED(hr)) { -#if _DEBUG - printf("Failed to acquire mouse\n"); -#endif + printfDebug("Failed to acquire mouse\n"); } } @@ -178,7 +176,7 @@ } JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead - (JNIEnv * env, jclass clazz) + (JNIEnv * env, jclass clazz) { static DIDEVICEOBJECTDATA rgdod[EVENT_BUFFER_SIZE]; @@ -199,55 +197,41 @@ if (ret == DI_OK) { return bufferButtons(bufsize, rgdod); } else if (ret == DI_BUFFEROVERFLOW) { -#ifdef _DEBUG - printf("Buffer overflowed\n"); -#endif + printfDebug("Buffer overflowed\n"); } else if (ret == DIERR_INPUTLOST) { -#ifdef _DEBUG - printf("Input lost\n"); -#endif + printfDebug("Input lost\n"); } else if (ret == DIERR_NOTACQUIRED) { -#ifdef _DEBUG - printf("not acquired\n"); -#endif + printfDebug("not acquired\n"); } else if (ret == DIERR_INVALIDPARAM) { -#ifdef _DEBUG - printf("invalid parameter\n"); -#endif + printfDebug("invalid parameter\n"); } else if (ret == DIERR_NOTBUFFERED) { -#ifdef _DEBUG - printf("not buffered\n"); -#endif + printfDebug("not buffered\n"); } else if (ret == DIERR_NOTINITIALIZED) { -#ifdef _DEBUG - printf("not inited\n"); -#endif + printfDebug("not inited\n"); } else { -#ifdef _DEBUG - printf("unknown keyboard error\n"); -#endif + printfDebug("unknown keyboard error\n"); } return 0; } /* - * Class: org_lwjgl_input_Mouse - * Method: nIsNativeCursorSupported + * Class: org_lwjgl_input_Mouse + * Method: nIsNativeCursorSupported * Signature: ()I */ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetNativeCursorCaps - (JNIEnv *env, jclass clazz) + (JNIEnv *env, jclass clazz) { return org_lwjgl_input_Mouse_CURSOR_ONE_BIT_TRANSPARENCY; } /* - * Class: org_lwjgl_input_Mouse - * Method: nSetNativeCursor + * Class: org_lwjgl_input_Mouse + * Method: nSetNativeCursor * Signature: (I)V */ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor - (JNIEnv *env, jclass clazz, jlong cursor_handle) + (JNIEnv *env, jclass clazz, jlong cursor_handle) { if (mDIDevice == NULL) throwException(env, "null device!"); @@ -288,30 +272,30 @@ } /* - * Class: org_lwjgl_input_Mouse - * Method: nGetMaxCursorSize + * Class: org_lwjgl_input_Mouse + * Method: nGetMaxCursorSize * Signature: ()I */ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetMaxCursorSize - (JNIEnv *env, jclass clazz) + (JNIEnv *env, jclass clazz) { return GetSystemMetrics(SM_CXCURSOR); } /* - * Class: org_lwjgl_input_Mouse - * Method: nGetMaxCursorSize + * Class: org_lwjgl_input_Mouse + * Method: nGetMaxCursorSize * Signature: ()I */ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetMinCursorSize - (JNIEnv *env, jclass clazz) + (JNIEnv *env, jclass clazz) { return GetSystemMetrics(SM_CXCURSOR); } /* - * Class: org_lwjgl_input_Mouse - * Method: nDestroy + * Class: org_lwjgl_input_Mouse + * Method: nDestroy * Signature: ()V */ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nDestroy(JNIEnv *env, jclass clazz) { @@ -320,25 +304,25 @@ } /* - * Class: org_lwjgl_input_Controller - * Method: nPoll + * Class: org_lwjgl_input_Controller + * Method: nPoll * Signature: ()V */ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll(JNIEnv * env, jclass clazz) { - mDIDevice->Acquire(); - UpdateMouseFields(env, clazz); + mDIDevice->Acquire(); + UpdateMouseFields(env, clazz); } /** * Shutdown DI */ void ShutdownMouse() { - // release device - if (mDIDevice != NULL) { - mDIDevice->Unacquire(); - mDIDevice->Release(); - mDIDevice = NULL; - } + // release device + if (mDIDevice != NULL) { + mDIDevice->Unacquire(); + mDIDevice->Release(); + mDIDevice = NULL; + } } /** * Enumerates the capabilities of the Mouse attached to the system @@ -347,21 +331,17 @@ HRESULT hr; hr = mDIDevice->EnumObjects(EnumMouseObjectsCallback, NULL, DIDFT_ALL); if FAILED(hr) { -#if _DEBUG - printf("EnumObjects failed\n"); -#endif + printfDebug("EnumObjects failed\n"); mCreate_success = false; return; } - + //check for > 4 buttons - need to clamp since we're using dx 5 if(mButtoncount > 4) { mButtoncount = 4; -#ifdef _DEBUG - printf("WARNING: Clamping to 4 mouse buttons\n"); -#endif + printfDebug("WARNING: Clamping to 4 mouse buttons\n"); } - + mCreate_success = true; } @@ -369,51 +349,43 @@ * Callback from EnumObjects. Called for each "object" on the Mouse. */ BOOL CALLBACK EnumMouseObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) { -#if _DEBUG - printf("found %s\n", lpddoi->tszName); -#endif - if(lpddoi->guidType == GUID_Button) { - mButtoncount++; - } else if(lpddoi->guidType == GUID_XAxis) { - } else if(lpddoi->guidType == GUID_YAxis) { - } else if(lpddoi->guidType == GUID_ZAxis) { - mHaswheel = 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) { + mButtoncount++; + } else if(lpddoi->guidType == GUID_XAxis) { + } else if(lpddoi->guidType == GUID_YAxis) { + } else if(lpddoi->guidType == GUID_ZAxis) { + mHaswheel = true; + } else { + printfDebug("Unhandled object found: %s\n", lpddoi->tszName); + } + return DIENUM_CONTINUE; } /** * Creates the specified device as a Mouse */ void CreateMouse() { - HRESULT hr; - hr = lpdi->CreateDevice(GUID_SysMouse, &mDIDevice, NULL); - if FAILED(hr) { -#if _DEBUG - printf("CreateDevice failed\n"); -#endif - mCreate_success = false; - return; - } - mCreate_success = true; + HRESULT hr; + hr = lpdi->CreateDevice(GUID_SysMouse, &mDIDevice, NULL); + if FAILED(hr) { + printfDebug("CreateDevice failed\n"); + mCreate_success = false; + return; + } + mCreate_success = true; } /** * Sets up the Mouse properties */ void SetupMouse() { - // set Mouse data format - if(mDIDevice->SetDataFormat(&c_dfDIMouse) != DI_OK) { -#if _DEBUG - printf("SetDataFormat failed\n"); -#endif - mCreate_success = false; - return; - } + // set Mouse data format + if(mDIDevice->SetDataFormat(&c_dfDIMouse) != DI_OK) { + printfDebug("SetDataFormat failed\n"); + mCreate_success = false; + return; + } DIPROPDWORD dipropdw; dipropdw.diph.dwSize = sizeof(DIPROPDWORD); @@ -424,14 +396,12 @@ mDIDevice->SetProperty(DIPROP_BUFFERSIZE, &dipropdw.diph); // set the cooperative level - if(mDIDevice->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) { -#if _DEBUG - printf("SetCooperativeLevel failed\n"); -#endif - mCreate_success = false; - return; - } - mCreate_success = true; + if(mDIDevice->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) { + printfDebug("SetCooperativeLevel failed\n"); + mCreate_success = false; + return; + } + mCreate_success = true; } static int cap(int val, int min, int max) { @@ -471,8 +441,8 @@ * Updates the fields on the Mouse */ static void UpdateMouseFields(JNIEnv *env, jclass clsMouse) { - HRESULT hRes; - DIMOUSESTATE diMouseState; // State of Mouse + HRESULT hRes; + DIMOUSESTATE diMouseState; // State of Mouse int dx, dy; // get data from the Mouse @@ -486,13 +456,8 @@ // if so, then attempt to reacquire. if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) { mDIDevice->Acquire(); -#if _DEBUG - //printf("DIERR_INPUTLOST, reaquiring input : mCreate_success=%d\n", mCreate_success); -#endif } else { -#if _DEBUG - printf("Error getting mouse state: %d\n", hRes); -#endif + printfDebug("Error getting mouse state: %d\n", hRes); } } @@ -523,8 +488,8 @@ * Caches the field ids for quicker access */ void CacheMouseFields(JNIEnv* env, jclass clsMouse) { - fidMButtons = env->GetStaticFieldID(clsMouse, "buttons", "[B"); - fidMDX = env->GetStaticFieldID(clsMouse, "dx", "I"); - fidMDY = env->GetStaticFieldID(clsMouse, "dy", "I"); - fidMDWheel = env->GetStaticFieldID(clsMouse, "dwheel", "I"); + fidMButtons = env->GetStaticFieldID(clsMouse, "buttons", "[B"); + fidMDX = env->GetStaticFieldID(clsMouse, "dx", "I"); + fidMDY = env->GetStaticFieldID(clsMouse, "dy", "I"); + fidMDWheel = env->GetStaticFieldID(clsMouse, "dwheel", "I"); } Index: org_lwjgl_opengl_Window.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/win32/org_lwjgl_opengl_Window.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_opengl_Window.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- org_lwjgl_opengl_Window.cpp 17 Nov 2003 07:45:14 -0000 1.12 +++ org_lwjgl_opengl_Window.cpp 15 Dec 2003 11:49:17 -0000 1.13 @@ -97,9 +97,7 @@ return -1; } -#ifdef _DEBUG - printf("Pixel format is %d\n", iPixelFormat); -#endif + printfDebug("Pixel format is %d\n", iPixelFormat); // make that the pixel format of the device context if (SetPixelFormat(hdc, iPixelFormat, &pfd) == FALSE) { @@ -161,22 +159,20 @@ // Create input HRESULT ret = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &lpdi, NULL); if (ret != DI_OK && ret != DIERR_BETADIRECTINPUTVERSION ) { -#ifdef _DEBUG - printf("Failed to create directinput"); + printfDebug("Failed to create directinput"); switch (ret) { case DIERR_INVALIDPARAM : - printf(" - Invalid parameter\n"); + printfDebug(" - Invalid parameter\n"); break; case DIERR_OLDDIRECTINPUTVERSION : - printf(" - Old Version\n"); + printfDebug(" - Old Version\n"); break; case DIERR_OUTOFMEMORY : - printf(" - Out Of Memory\n"); + printfDebug(" - Out Of Memory\n"); break; default: - printf(" - Unknown failure\n"); + printfDebug(" - Unknown failure\n"); } -#endif return false; } else { return true; @@ -190,31 +186,23 @@ { // Release DirectInput if (lpdi != NULL) { -#ifdef _DEBUG - printf("Destroying directinput\n"); -#endif + printfDebug("Destroying directinput\n"); lpdi->Release(); lpdi = NULL; } // Release device context if (hdc != NULL && hwnd != NULL) { -#ifdef _DEBUG - printf("Releasing DC\n"); -#endif + printfDebug("Releasing DC\n"); ReleaseDC(hwnd, hdc); } // Close the window if (hwnd != NULL) { -#ifdef _DEBUG - printf("Destroy window\n"); -#endif + printfDebug("Destroy window\n"); // Vape the window DestroyWindow(hwnd); -#ifdef _DEBUG - printf("Destroyed window\n"); -#endif + printfDebug("Destroyed window\n"); hwnd = NULL; } } @@ -324,14 +312,10 @@ windowClass.lpszClassName = WINDOWCLASSNAME; if (RegisterClass(&windowClass) == 0) { -#ifdef _DEBUG - printf("Failed to register window class\n"); -#endif + printfDebug("Failed to register window class\n"); return false; } -#ifdef _DEBUG - printf("Window registered\n"); -#endif + printfDebug("Window registered\n"); oneShotInitialised = true; } @@ -413,15 +397,11 @@ NULL); if (hwnd == NULL) { -#ifdef _DEBUG - printf("Failed to create window\n"); -#endif + printfDebug("Failed to create window\n"); return false; } -#ifdef _DEBUG - printf("Created window\n"); -#endif + printfDebug("Created window\n"); ShowWindow(hwnd, SW_SHOW); UpdateWindow(hwnd); @@ -578,9 +558,7 @@ // Delete the rendering context if (hglrc != NULL) { -#ifdef _DEBUG - printf("Delete GL context\n"); -#endif + printfDebug("Deleting GL context\n"); wglDeleteContext(hglrc); hglrc = NULL; } |