From 0f5281e24fab11859a5732e1c6438ab5c3b7d750 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 12 May 2005 07:47:07 +0000 Subject: [PATCH] OpenAL: Made the openal library path returned by the current ClassLoader and cwd more override java.library.path. Converted some printfDebug to printfDebugJava --- src/java/org/lwjgl/LWJGLUtil.java | 18 ++++----- src/java/org/lwjgl/openal/AL.java | 1 + src/native/common/extal.c | 13 +++---- src/native/macosx/org_lwjgl_input_Mouse.c | 2 +- src/native/win32/display.c | 10 ++--- src/native/win32/org_lwjgl_Sys.c | 4 +- src/native/win32/org_lwjgl_input_Keyboard.c | 18 ++++----- src/native/win32/org_lwjgl_input_Mouse.c | 38 +++++++++---------- src/native/win32/org_lwjgl_opengl_Pbuffer.c | 2 +- ..._lwjgl_opengl_Win32ContextImplementation.c | 2 +- 10 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/java/org/lwjgl/LWJGLUtil.java b/src/java/org/lwjgl/LWJGLUtil.java index 78df0a29..d8ea6f8d 100644 --- a/src/java/org/lwjgl/LWJGLUtil.java +++ b/src/java/org/lwjgl/LWJGLUtil.java @@ -76,11 +76,11 @@ public class LWJGLUtil { * * @param libNames List of library names to look for, in the form of Local Library name, Platform library name. * At least 6 names must be passed. 2 for each supported platform in the following order: Windows, Linux, MacOSX. - * @param classloader The classloader to ask for librariy paths + * @param classloader The classloader to ask for library paths * @return Paths to located libraries, if any */ public static String[] getLibraryPaths(String[] libNames, ClassLoader classloader) throws LWJGLException { - // need to pass path of possible locations of IL to native side + // need to pass path of possible locations of library to native side List possible_paths = new ArrayList(); String libname; @@ -102,13 +102,6 @@ public class LWJGLUtil { throw new LWJGLException("Unknown platform: " + getPlatform()); } - // Add all possible paths from java.library.path - StringTokenizer st = new StringTokenizer(System.getProperty("java.library.path"), File.pathSeparator); - while (st.hasMoreTokens()) { - String path = st.nextToken(); - possible_paths.add(path + File.separator + platform_lib_name); - } - String classloader_path = LWJGLUtil.getPathFromClassLoader(libname, classloader); if (classloader_path != null) { LWJGLUtil.log("getPathFromClassLoader: Path found: " + classloader_path); @@ -125,6 +118,13 @@ public class LWJGLUtil { //add cwd path possible_paths.add(platform_lib_name); + // Add all possible paths from java.library.path + StringTokenizer st = new StringTokenizer(System.getProperty("java.library.path"), File.pathSeparator); + while (st.hasMoreTokens()) { + String path = st.nextToken(); + possible_paths.add(path + File.separator + platform_lib_name); + } + //create needed string array String[] paths = new String[possible_paths.size()]; possible_paths.toArray(paths); diff --git a/src/java/org/lwjgl/openal/AL.java b/src/java/org/lwjgl/openal/AL.java index 1b14209a..4c7d3017 100644 --- a/src/java/org/lwjgl/openal/AL.java +++ b/src/java/org/lwjgl/openal/AL.java @@ -137,6 +137,7 @@ public final class AL { "lwjglaudio", "lwjglaudio.dll", "openal", "libopenal.so", "openal", "openal.dylib"}, AL.class.getClassLoader()); + LWJGLUtil.log("Found " + oalPaths.length + " OpenAL paths"); nCreate(oalPaths); created = true; diff --git a/src/native/common/extal.c b/src/native/common/extal.c index 076954ff..2d710262 100644 --- a/src/native/common/extal.c +++ b/src/native/common/extal.c @@ -109,28 +109,28 @@ static void* extal_GetProcAddress(const char* function) { static void tryLoadLibrary(JNIEnv *env, jstring path) { #ifdef _WIN32 char *path_str = GetStringNativeChars(env, path); - printfDebug("Testing '%s'\n", path_str); + printfDebugJava(env, "Testing '%s'", path_str); handleOAL = LoadLibrary(path_str); if (handleOAL != NULL) { - printfDebugJava(env, "Found OpenAL at '%s'\n", path_str); + printfDebugJava(env, "Found OpenAL at '%s'", path_str); } free(path_str); #endif #ifdef _X11 char *path_str = GetStringNativeChars(env, path); - printfDebug("Testing '%s'\n", path_str); + printfDebugJava(env, "Testing '%s'", path_str); handleOAL = dlopen(path_str, RTLD_LAZY); if (handleOAL != NULL) { - printfDebugJava(env, "Found OpenAL at '%s'\n", path_str); + printfDebugJava(env, "Found OpenAL at '%s'", path_str); } free(path_str); #endif #ifdef _MACOSX const char *path_str = (*env)->GetStringUTFChars(env, path, NULL); - printfDebug("Testing '%s'\n", path_str); + printfDebugJava(env, "Testing '%s'", path_str); handleOAL = NSAddImage(path_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR); if (handleOAL != NULL) { - printfDebugJava(env, "Found OpenAL at '%s'\n", path_str); + printfDebugJava(env, "Found OpenAL at '%s'", path_str); } (*env)->ReleaseStringUTFChars(env, path, path_str); #endif @@ -144,7 +144,6 @@ static bool LoadOpenAL(JNIEnv *env, jobjectArray oalPaths) { int i; jstring path; - printfDebug("Found %d OpenAL paths\n", (int)pathcount); for(i=0;iGetObjectArrayElement(env, oalPaths, i); tryLoadLibrary(env, path); diff --git a/src/native/macosx/org_lwjgl_input_Mouse.c b/src/native/macosx/org_lwjgl_input_Mouse.c index a0d5013e..f337295e 100644 --- a/src/native/macosx/org_lwjgl_input_Mouse.c +++ b/src/native/macosx/org_lwjgl_input_Mouse.c @@ -69,7 +69,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_getMouseDeltas(JNIEnv CGGetLastMouseDelta(&dx, &dy); int buffer_length = (*env)->GetDirectBufferCapacity(env, delta_buffer); if (buffer_length != 2) { - printfDebug("Delta buffer not large enough!\n"); + printfDebugJava(env, "Delta buffer not large enough!"); return; } jint *buffer = (*env)->GetDirectBufferAddress(env, delta_buffer); diff --git a/src/native/win32/display.c b/src/native/win32/display.c index 6a96c690..b98ed671 100644 --- a/src/native/win32/display.c +++ b/src/native/win32/display.c @@ -118,7 +118,7 @@ static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) { } } } - printfDebug("Found %d displaymodes\n", n); + printfDebugJava(env, "Found %d displaymodes", n); ret = (*env)->NewObjectArray(env, n, displayModeClass, NULL); for (i = 0; i < n; i++) { @@ -155,12 +155,12 @@ void switchDisplayMode(JNIEnv * env, jobject mode) if (cdsret != DISP_CHANGE_SUCCESSFUL) { // Failed: so let's check to see if it's a wierd dual screen display - printfDebug("Failed to set display mode... assuming dual monitors\n"); + printfDebugJava(env, "Failed to set display mode... assuming dual monitors"); devmode.dmPelsWidth = width * 2; cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN); if (cdsret != DISP_CHANGE_SUCCESSFUL) { - printfDebug("Failed to set display mode using dual monitors\n"); + printfDebugJava(env, "Failed to set display mode using dual monitors"); throwException(env, "Failed to set display mode."); return; } @@ -227,7 +227,7 @@ jobject initDisplay(JNIEnv * env) // Get the default gamma ramp if (GetDeviceGammaRamp(screenDC, originalGamma) == FALSE) { - printfDebug("Failed to get initial device gamma\n"); + printfDebugJava(env, "Failed to get initial device gamma"); } memcpy(currentGamma, originalGamma, sizeof(WORD)*GAMMA_SIZE); ReleaseDC(NULL, screenDC); @@ -238,7 +238,7 @@ void resetDisplayMode(JNIEnv * env) { // Return device gamma to normal HDC screenDC = GetDC(NULL); if (!SetDeviceGammaRamp(screenDC, originalGamma)) { - printfDebug("Could not reset device gamma\n"); + printfDebugJava(env, "Could not reset device gamma"); } ReleaseDC(NULL, screenDC); diff --git a/src/native/win32/org_lwjgl_Sys.c b/src/native/win32/org_lwjgl_Sys.c index 8433652f..b11ba7ba 100644 --- a/src/native/win32/org_lwjgl_Sys.c +++ b/src/native/win32/org_lwjgl_Sys.c @@ -87,7 +87,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_NativeSysImplementation_alert char * cTitleBarText = GetStringNativeChars(env, title); MessageBox(getCurrentHWND(), eMessageText, cTitleBarText, MB_OK | MB_TOPMOST); - printfDebug("*** Alert ***%s\n%s\n", cTitleBarText, eMessageText); + printfDebugJava(env, "*** Alert ***%s\n%s\n", cTitleBarText, eMessageText); free(eMessageText); free(cTitleBarText); @@ -129,7 +129,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_NativeSysImplementation_openURL &pi ) // Pointer to PROCESS_INFORMATION structure. ) { - printfDebug("Failed to open URL %s\n", urlString); + printfDebugJava(env, "Failed to open URL %s", urlString); return JNI_FALSE; } diff --git a/src/native/win32/org_lwjgl_input_Keyboard.c b/src/native/win32/org_lwjgl_input_Keyboard.c index 86fc0be5..9f23ce35 100644 --- a/src/native/win32/org_lwjgl_input_Keyboard.c +++ b/src/native/win32/org_lwjgl_input_Keyboard.c @@ -98,7 +98,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createKeyboard ret = IDirectInputDevice_Acquire(lpdiKeyboard); if(FAILED(ret)) { - printfDebug("Failed to acquire keyboard\n"); + printfDebugJava(env, "Failed to acquire keyboard"); } osvi.dwOSVersionInfoSize = sizeof(osvi); GetVersionEx(&osvi); @@ -126,7 +126,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_destroyKeyboard } // Release DirectInput if (lpdi != NULL) { - printfDebug("Destroying directinput\n"); + printfDebugJava(env, "Destroying directinput"); IDirectInput_Release(lpdi); lpdi = NULL; } @@ -260,19 +260,19 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readKeyboard current_di_event++; } } else if (ret == DI_BUFFEROVERFLOW) { - printfDebug("Keyboard buffer overflowed\n"); + printfDebugJava(env, "Keyboard buffer overflowed"); } else if (ret == DIERR_INPUTLOST) { - printfDebug("Input lost\n"); + printfDebugJava(env, "Input lost"); } else if (ret == DIERR_NOTACQUIRED) { - printfDebug("not acquired\n"); + printfDebugJava(env, "not acquired"); } else if (ret == DIERR_INVALIDPARAM) { - printfDebug("invalid parameter\n"); + printfDebugJava(env, "invalid parameter"); } else if (ret == DIERR_NOTBUFFERED) { - printfDebug("not buffered\n"); + printfDebugJava(env, "not buffered"); } else if (ret == DIERR_NOTINITIALIZED) { - printfDebug("not inited\n"); + printfDebugJava(env, "not inited"); } else { - printfDebug("unknown keyboard error\n"); + printfDebugJava(env, "unknown keyboard error"); } return num_events; } diff --git a/src/native/win32/org_lwjgl_input_Mouse.c b/src/native/win32/org_lwjgl_input_Mouse.c index a5e5b0d0..ea17f95a 100644 --- a/src/native/win32/org_lwjgl_input_Mouse.c +++ b/src/native/win32/org_lwjgl_input_Mouse.c @@ -75,7 +75,7 @@ static event_queue_t event_queue; // Function prototypes (defined in the cpp file, since header file is generic across platforms BOOL CALLBACK EnumMouseObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef); -void ShutdownMouse(); +void ShutdownMouse(JNIEnv *env); void InitializeMouseFields(); void UpdateMouseFields(JNIEnv *env, jobject coord_buffer_obj, jobject button_buffer_obj); @@ -123,7 +123,7 @@ static bool EnumerateMouseCapabilities(JNIEnv *env) { //check for > 4 buttons - need to clamp since we're using dx 5 if(mButtoncount > 4) { mButtoncount = 4; - printfDebug("WARNING: Clamping to 4 mouse buttons\n"); + printfDebugJava(env, "WARNING: Clamping to 4 mouse buttons\n"); } return true; } @@ -194,14 +194,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createMouse(JNIEnv *en if (mFirstTimeInitialization) { /* Enumerate capabilities of Mouse */ if (!EnumerateMouseCapabilities(env)) { - ShutdownMouse(); + ShutdownMouse(env); return; } mFirstTimeInitialization = false; } /* Do setup of Mouse */ if (!SetupMouse(env)) { - ShutdownMouse(); + ShutdownMouse(env); return; } created = true; @@ -280,7 +280,7 @@ static void copyDXEvents(int num_di_events, DIDEVICEOBJECTDATA *di_buffer) { putMouseEventWithCoords(-1, 0, dx, -dy, dwheel); } -static void readDXBuffer() { +static void readDXBuffer(JNIEnv *env) { DIDEVICEOBJECTDATA rgdod[EVENT_BUFFER_SIZE]; DWORD num_di_events = EVENT_BUFFER_SIZE; @@ -299,19 +299,19 @@ static void readDXBuffer() { if (ret == DI_OK) { copyDXEvents(num_di_events, rgdod); } else if (ret == DI_BUFFEROVERFLOW) { - printfDebug("Buffer overflowed\n"); + printfDebugJava(env, "Buffer overflowed"); } else if (ret == DIERR_INPUTLOST) { - printfDebug("Input lost\n"); + printfDebugJava(env, "Input lost"); } else if (ret == DIERR_NOTACQUIRED) { - printfDebug("not acquired\n"); + printfDebugJava(env, "not acquired"); } else if (ret == DIERR_INVALIDPARAM) { - printfDebug("invalid parameter\n"); + printfDebugJava(env, "invalid parameter"); } else if (ret == DIERR_NOTBUFFERED) { - printfDebug("not buffered\n"); + printfDebugJava(env, "not buffered"); } else if (ret == DIERR_NOTINITIALIZED) { - printfDebug("not inited\n"); + printfDebugJava(env, "not inited"); } else { - printfDebug("unknown keyboard error\n"); + printfDebugJava(env, "unknown keyboard error"); } } @@ -321,7 +321,7 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readMouse jint* buffer_ptr = (jint *)(*env)->GetDirectBufferAddress(env, buffer_obj) + buffer_position; int buffer_size = ((*env)->GetDirectBufferCapacity(env, buffer_obj))/sizeof(jint) - buffer_position; if (mouse_grabbed) { - readDXBuffer(); + readDXBuffer(env); } else { handleMessages(); } @@ -345,7 +345,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_setNativeCursor } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_destroyMouse(JNIEnv *env, jobject self) { - ShutdownMouse(); + ShutdownMouse(env); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_pollMouse(JNIEnv * env, jobject self, jobject coord_buffer_obj, jobject button_buffer_obj) { @@ -408,17 +408,17 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_grabMouse /** * Shutdown DI */ -static void ShutdownMouse() { +static void ShutdownMouse(JNIEnv *env) { // release device if (mDIDevice != NULL) { - printfDebug("Releasing mouse DI device\n"); + printfDebugJava(env, "Releasing mouse DI device"); IDirectInputDevice_Unacquire(mDIDevice); IDirectInputDevice_Release(mDIDevice); mDIDevice = NULL; } // Release DirectInput if (lpdi != NULL) { - printfDebug("Releasing directinput\n"); + printfDebugJava(env, "Releasing directinput"); IDirectInput_Release(lpdi); lpdi = NULL; } @@ -465,7 +465,7 @@ static void UpdateMouseFields(JNIEnv *env, jobject coord_buffer_obj, jobject but int num_buttons; int buttons_length = (int)(*env)->GetDirectBufferCapacity(env, button_buffer_obj); if (coords_length < 3) { - printfDebug("ERROR: Not enough space in coords array: %d < 3\n", coords_length); + printfDebugJava(env, "ERROR: Not enough space in coords array: %d < 3", coords_length); return; } @@ -485,7 +485,7 @@ static void UpdateMouseFields(JNIEnv *env, jobject coord_buffer_obj, jobject but if (hRes != DI_OK) return; } else { - printfDebug("Error getting mouse state: %d\n", hRes); + printfDebugJava(env, "Error getting mouse state: %d", hRes); return; } } diff --git a/src/native/win32/org_lwjgl_opengl_Pbuffer.c b/src/native/win32/org_lwjgl_opengl_Pbuffer.c index 48959cc8..d315de89 100644 --- a/src/native/win32/org_lwjgl_opengl_Pbuffer.c +++ b/src/native/win32/org_lwjgl_opengl_Pbuffer.c @@ -93,7 +93,7 @@ static bool getExtensions(JNIEnv *env, WGLExtensions *extensions, jobject pixel_ } extgl_InitWGL(extensions); if (!wglMakeCurrent(saved_hdc, saved_context)) - printfDebug("ERROR: Could not restore current context\n"); + printfDebugJava(env, "ERROR: Could not restore current context"); closeWindow(&dummy_hwnd, &dummy_hdc); wglDeleteContext(dummy_context); return true; diff --git a/src/native/win32/org_lwjgl_opengl_Win32ContextImplementation.c b/src/native/win32/org_lwjgl_opengl_Win32ContextImplementation.c index c1bf37cb..3db094d8 100644 --- a/src/native/win32/org_lwjgl_opengl_Win32ContextImplementation.c +++ b/src/native/win32/org_lwjgl_opengl_Win32ContextImplementation.c @@ -88,7 +88,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_Win32ContextImplementation_nCrea } extgl_InitWGL(&extensions); if (!wglMakeCurrent(saved_hdc, saved_context)) - printfDebug("Failed to restore current context\n"); + printfDebugJava(env, "Failed to restore current context"); context_info = (Win32Context *)(*env)->GetDirectBufferAddress(env, context_handle); context_info->context = context; context_info->extensions = extensions;