From 7251a38930cd4c03ffe21a2ea705290bdb94bcc6 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 9 Mar 2005 13:06:17 +0000 Subject: [PATCH] OpenAL: Moved more library loading from native to java --- src/java/org/lwjgl/openal/AL.java | 63 ++++++++++++++------------- src/native/common/extal.c | 71 ++++--------------------------- src/native/common/extal.h | 3 +- 3 files changed, 42 insertions(+), 95 deletions(-) diff --git a/src/java/org/lwjgl/openal/AL.java b/src/java/org/lwjgl/openal/AL.java index 59d5abe1..69555bbe 100644 --- a/src/java/org/lwjgl/openal/AL.java +++ b/src/java/org/lwjgl/openal/AL.java @@ -35,6 +35,9 @@ import java.io.File; import java.lang.reflect.Method; import java.util.StringTokenizer; +import java.util.List; +import java.util.ArrayList; + import org.lwjgl.LWJGLException; import org.lwjgl.Sys; @@ -130,49 +133,49 @@ public final class AL { private static String[] getOALPaths() throws LWJGLException { // need to pass path of possible locations of OAL to native side - String libpath = System.getProperty("java.library.path"); - String seperator = System.getProperty("path.separator"); - String jwsLibname; - + List possible_paths = new ArrayList(); + String osName = System.getProperty("os.name"); + + String libname; if (osName.startsWith("Win")) { - jwsLibname = "lwjglaudio"; + libname = "lwjglaudio"; } else if (osName.startsWith("Lin")) { - jwsLibname = "openal"; + libname = "openal"; } else if (osName.startsWith("Mac")) { - jwsLibname = "openal"; + libname = "openal"; } else { throw new LWJGLException("Unknown platform: "+osName); } - String jwsPath = getPathFromClassLoader(jwsLibname); - if (jwsPath != null) { - Sys.log("getPathFromClassLoader: Path found: " + jwsPath); - libpath += seperator - + jwsPath.substring(0, jwsPath.lastIndexOf(File.separator)); - } - String lwjgl_jws_path = getPathFromClassLoader("lwjgl"); - if (lwjgl_jws_path != null) { - Sys.log("getPathFromClassLoader: Path found: " + lwjgl_jws_path); - libpath += seperator - + lwjgl_jws_path.substring(0, lwjgl_jws_path.lastIndexOf(File.separator)); - } - StringTokenizer st = new StringTokenizer(libpath, seperator); + String platform_lib_name = System.mapLibraryName(libname); - //create needed string array - String[] oalPaths = new String[st.countTokens() + 1]; - - //build paths - for (int i = 0; i < oalPaths.length - 1; i++) { - oalPaths[i] = st.nextToken() + File.separator; + // Add all possible paths from java.library.path + String java_library_path = System.getProperty("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); } - - for(int i=0 ; i #include #include -const struct mach_header* handleOAL = NULL; +static const struct mach_header* handleOAL; #endif -alGetProcAddressPROC alGetProcAddress = NULL; +typedef ALvoid* (ALAPIENTRY *alGetProcAddressPROC)( ALubyte* fname ); +static alGetProcAddressPROC alGetProcAddress = NULL; /* Loads OpenAL */ static bool LoadOpenAL(JNIEnv *env, jobjectArray oalPaths); @@ -108,35 +106,6 @@ static void* extal_GetProcAddress(const char* function) { return p; } -/** - * Concatenate two strings - */ -static char *concatenate(const char *str1, const char *str2) { - int length1 = strlen(str1); - int length2 = strlen(str2); - char *str = (char *)calloc(length1 + length2 + 1, sizeof(char)); - strncpy(str, str1, length1); - strncpy(str + length1, str2, length2 + 1); - return str; -} - -#ifdef _X11 -static void closeVorbisLibs(void) { - if (handleOGG != NULL) { - dlclose(handleOGG); - handleOGG = NULL; - } - if (handleVorbis != NULL) { - dlclose(handleVorbis); - handleVorbis = NULL; - } - if (handleVorbisFile != NULL) { - dlclose(handleVorbisFile); - handleVorbisFile = NULL; - } -} -#endif - /** * Loads the OpenAL Library */ @@ -145,7 +114,6 @@ static bool LoadOpenAL(JNIEnv *env, jobjectArray oalPaths) { int i; jstring path; char *path_str; - char *lib_str; printfDebug("Found %d OpenAL paths\n", (int)pathcount); for(i=0;i