OSDN Git Service

Refactored native loading. You may hate it.
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Fri, 21 Jan 2011 03:37:34 +0000 (03:37 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Fri, 21 Jan 2011 03:37:34 +0000 (03:37 +0000)
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplication.java
backends/gdx-backend-jogl/libs/gdx-backend-jogl-natives.jar
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglApplication.java
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglNativesLoader.java
backends/gdx-backend-lwjgl/libs/gdx-backend-lwjgl-natives.jar
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglNativesLoader.java
backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleApplication.java
backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALAudio.java
gdx/src/com/badlogic/gdx/Version.java
gdx/src/com/badlogic/gdx/graphics/g2d/BitmapFont.java
gdx/src/com/badlogic/gdx/utils/GdxNativesLoader.java

index 8a8b33f..d96414c 100644 (file)
@@ -23,8 +23,8 @@ import android.view.Gravity;
 import android.view.View;\r
 import android.view.Window;\r
 import android.view.WindowManager;\r
-\r
 import android.widget.FrameLayout;\r
+\r
 import com.badlogic.gdx.Application;\r
 import com.badlogic.gdx.ApplicationListener;\r
 import com.badlogic.gdx.Audio;\r
@@ -32,12 +32,12 @@ import com.badlogic.gdx.Files;
 import com.badlogic.gdx.Gdx;\r
 import com.badlogic.gdx.Graphics;\r
 import com.badlogic.gdx.Input;\r
-import com.badlogic.gdx.Version;\r
 import com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy;\r
 import com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake;\r
 import com.badlogic.gdx.backends.android.surfaceview.ResolutionStrategy;\r
 import com.badlogic.gdx.graphics.GL10;\r
 import com.badlogic.gdx.graphics.GL11;\r
+import com.badlogic.gdx.utils.GdxNativesLoader;\r
 \r
 /**\r
  * An implementation of the {@link Application} interface for Android. Create an {@link Activity} that derives from this class. In\r
@@ -47,9 +47,8 @@ import com.badlogic.gdx.graphics.GL11;
  * @author mzechner\r
  */\r
 public class AndroidApplication extends Activity implements Application {\r
-\r
     static {\r
-        Version.loadLibrary();\r
+        GdxNativesLoader.load();\r
     }\r
 \r
     protected AndroidGraphics graphics;\r
index fac2f3a..b84b35a 100644 (file)
Binary files a/backends/gdx-backend-jogl/libs/gdx-backend-jogl-natives.jar and b/backends/gdx-backend-jogl/libs/gdx-backend-jogl-natives.jar differ
index 94ae49c..8a2df84 100644 (file)
@@ -41,10 +41,6 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
  * \r
  */\r
 public final class JoglApplication implements Application {\r
-       static {\r
-               Version.loadLibrary();\r
-       }\r
-\r
        JoglGraphics graphics;\r
        JoglInput input;\r
        JoglFiles files;\r
@@ -80,7 +76,7 @@ public final class JoglApplication implements Application {
        }\r
 \r
        void initialize (ApplicationListener listener, String title, int width, int height, boolean useGL20) {\r
-               JoglNativesLoader.loadLibraries();\r
+               JoglNativesLoader.load();\r
                graphics = new JoglGraphics(listener, title, width, height, useGL20);\r
                input = new JoglInput(graphics.getCanvas());\r
                audio = new OpenALAudio();\r
index d5a585e..f91878c 100644 (file)
 \r
 package com.badlogic.gdx.backends.jogl;\r
 \r
-import java.io.BufferedOutputStream;\r
-import java.io.File;\r
-import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-\r
+import com.badlogic.gdx.utils.GdxNativesLoader;\r
 import com.sun.opengl.impl.NativeLibLoader;\r
 \r
+import static com.badlogic.gdx.utils.GdxNativesLoader.*;\r
+\r
 public class JoglNativesLoader {\r
-       static boolean nativesLoaded = false;\r
+       static private boolean nativesLoaded = false;\r
 \r
        /**\r
         * loads the necessary libraries depending on the operating system\r
         */\r
-       static void loadLibraries () {\r
+       static void load () {\r
+               GdxNativesLoader.load();\r
+\r
                if (nativesLoaded) return;\r
 \r
                NativeLibLoader.disableLoading();\r
@@ -43,82 +41,33 @@ public class JoglNativesLoader {
                                System.err.println("WARNING: Unable to load native jawt library: '" + ex.getMessage() + "'");\r
                        }\r
                }\r
-               loadLibrary("gluegen-rt");\r
-               loadLibrary("jogl_awt");\r
-               loadLibrary("jogl");\r
 \r
-               String os = System.getProperty("os.name");\r
-               boolean is64Bit = System.getProperty("os.arch").equals("amd64");\r
-               if (os.contains("Windows")) {\r
-                       load("/native/windows/", is64Bit ? "lwjgl64.dll" : "lwjgl.dll", false);\r
-                       load("/native/windows/", is64Bit ? "OpenAL64.dll" : "OpenAL32.dll", false);\r
-               } else if (os.contains("Linux")) {\r
-                       load("/native/linux/", is64Bit ? "liblwjgl64.so" : "liblwjgl.so", false);\r
-                       load("/native/linux/", is64Bit ? "libopenal64.so" : "libopenal.so", false);\r
-               } else if (os.contains("Mac")) {\r
-                       load("/native/macosx/", "liblwjgl.jnilib", false);\r
-                       load("/native/macosx/", "libopenal.dylib", false);\r
+               if (isWindows) {\r
+                       loadLibrary("gluegen-rt-win32.dll", "gluegen-rt-win64.dll");\r
+                       loadLibrary("jogl_awt-win32.dll", "jogl_awt-win64.dll");\r
+                       loadLibrary("jogl-win32.dll", "jogl-win64.dll");\r
+               } else if (isMac) {\r
+                       loadLibrary("libgluegen-rt.jnilib", "libgluegen-rt.jnilib");\r
+                       loadLibrary("libjogl_awt.jnilib", "libjogl_awt.jnilib");\r
+                       loadLibrary("libjogl.jnilib", "libjogl.jnilib");\r
+               } else if (isLinux) {\r
+                       loadLibrary("libgluegen-rt-linux32.so", "libgluegen-rt-linux64.so");\r
+                       loadLibrary("libjogl_awt-linux32.so", "libjogl_awt-linux64.so");\r
+                       loadLibrary("libjogl-linux32.so", "libjogl-linux64.so");\r
                }\r
-               System.setProperty("org.lwjgl.librarypath", new File(System.getProperty("java.io.tmpdir")).getAbsolutePath());\r
-\r
-               nativesLoaded = true;\r
-       }\r
 \r
-       /**\r
-        * helper method to load a specific library in an operation system dependant manner\r
-        * \r
-        * @param resource the name of the resource\r
-        */\r
-       private static void loadLibrary (String resource) {\r
-               String package_path = "/javax/media/";\r
-               String library = "";\r
-\r
-               String os = System.getProperty("os.name");\r
-               String arch = System.getProperty("os.arch");\r
-\r
-               if (os.contains("Windows")) {\r
-                       if (!arch.equals("amd64"))\r
-                               library = resource + "-win32.dll";\r
-                       else {\r
-                               library = resource + "-win64.dll";\r
-                       }\r
+               if (isWindows) {\r
+                       extractLibrary("OpenAL32.dll", "OpenAL64.dll");\r
+                       extractLibrary("lwjgl.dll", "lwjgl64.dll");\r
+               } else if (isMac) {\r
+                       extractLibrary("openal.dylib", "openal.dylib");\r
+                       extractLibrary("liblwjgl.jnilib", "liblwjgl.jnilib");\r
+               } else if (isLinux) {\r
+                       extractLibrary("libopenal.so", "libopenal64.so");\r
+                       extractLibrary("liblwjgl.so", "liblwjgl64.so");\r
                }\r
+               System.setProperty("org.lwjgl.librarypath", nativesDir.getAbsolutePath());\r
 \r
-               if (os.contains("Linux")) {\r
-                       if (!arch.equals("amd64"))\r
-                               library = "lib" + resource + "-linux32.so";\r
-                       else\r
-                               library = "lib" + resource + "-linux64.so";\r
-               }\r
-\r
-               if (os.contains("Mac")) {\r
-                       library = "lib" + resource + ".jnilib";\r
-               }\r
-               load(package_path, library, true);\r
-       }\r
-\r
-       private static void load (String package_path, String library, boolean stamped) {\r
-               String so = System.getProperty("java.io.tmpdir") + "/" + (stamped?System.nanoTime():"") + library;\r
-               InputStream in = JoglGraphics.class.getResourceAsStream(package_path + library);\r
-               if (in == null) throw new RuntimeException("couldn't find " + library + " in jar file.");\r
-\r
-               try {\r
-                       BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(so));\r
-                       byte[] bytes = new byte[1024 * 4];\r
-                       while (true) {\r
-                               int read_bytes = in.read(bytes);\r
-                               if (read_bytes == -1) break;\r
-\r
-                               out.write(bytes, 0, read_bytes);\r
-                       }\r
-                       out.close();\r
-                       in.close();\r
-                       System.load(so);\r
-               } catch (FileNotFoundException e) {\r
-                       if(stamped)\r
-                               throw new RuntimeException("couldn't write " + library + " to temporary file " + so);\r
-               } catch (IOException e) {\r
-                       throw new RuntimeException("couldn't write " + library + " to temporary file " + so);\r
-               }\r
+               nativesLoaded = true;\r
        }\r
 }\r
index 140f9ea..420e667 100644 (file)
Binary files a/backends/gdx-backend-lwjgl/libs/gdx-backend-lwjgl-natives.jar and b/backends/gdx-backend-lwjgl/libs/gdx-backend-lwjgl-natives.jar differ
index 9051003..b6f88ce 100644 (file)
 \r
 package com.badlogic.gdx.backends.lwjgl;\r
 \r
-import java.io.BufferedOutputStream;\r
 import java.io.File;\r
 import java.io.FileOutputStream;\r
+import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.lang.reflect.Method;\r
 \r
 import com.badlogic.gdx.Version;\r
-import com.badlogic.gdx.utils.GdxRuntimeException;\r
+import com.badlogic.gdx.utils.GdxNativesLoader;\r
+\r
+import static com.badlogic.gdx.utils.GdxNativesLoader.*;\r
 \r
 final class LwjglNativesLoader {\r
-       public static boolean load = true;\r
+       static public boolean load = true;\r
 \r
        static {\r
+               System.setProperty("org.lwjgl.input.Mouse.allowNegativeMouseCoords", "true");\r
+               // Don't extract natives if using JWS.\r
                try {\r
-                       System.setProperty("org.lwjgl.input.Mouse.allowNegativeMouseCoords", "true");\r
                        Method method = Class.forName("javax.jnlp.ServiceManager").getDeclaredMethod("lookup", new Class[] {String.class});\r
                        method.invoke(null, "javax.jnlp.PersistenceService");\r
                        load = false;\r
@@ -37,84 +40,19 @@ final class LwjglNativesLoader {
        }\r
 \r
        static void load () {\r
-               Version.loadLibrary();\r
-\r
+               GdxNativesLoader.load();\r
                if (!load) return;\r
-\r
-               String os = System.getProperty("os.name");\r
-               String arch = System.getProperty("os.arch");\r
-               boolean is64Bit = false;\r
-\r
-               if (arch.equals("amd64")) is64Bit = true;\r
-\r
-               if (os.contains("Windows")) loadLibrariesWindows(is64Bit);\r
-               if (os.contains("Linux")) loadLibrariesLinux(is64Bit);\r
-               if (os.contains("Mac")) loadLibrariesMac();\r
-\r
-               System.setProperty("org.lwjgl.librarypath", new File(System.getProperty("java.io.tmpdir")).getAbsolutePath());\r
-       }\r
-\r
-       private static void loadLibrariesWindows (boolean is64Bit) {\r
-               String[] libNames = null;\r
-               if (is64Bit)\r
-                       libNames = new String[] {"OpenAL64.dll", "lwjgl64.dll"};\r
-               else\r
-                       libNames = new String[] {"OpenAL32.dll", "lwjgl.dll"};\r
-\r
-               for (String libName : libNames)\r
-                       loadLibrary(libName, "/native/windows/", System.getProperty("java.io.tmpdir") + File.separator);\r
-       }\r
-\r
-       private static void loadLibrariesLinux (boolean is64Bit) {\r
-               String[] libNames = null;\r
-               if (is64Bit)\r
-                       libNames = new String[] {"libopenal64.so", "liblwjgl64.so"};\r
-               else\r
-                       libNames = new String[] {"libopenal.so", "liblwjgl.so"};\r
-\r
-               for (String libName : libNames)\r
-                       loadLibrary(libName, "/native/linux/", System.getProperty("java.io.tmpdir") + File.separator);\r
-       }\r
-\r
-       private static void loadLibrariesMac () {\r
-               String[] libNames = new String[] {"libopenal.dylib", "liblwjgl.jnilib"};\r
-               for (String libName : libNames)\r
-                       loadLibrary(libName, "/native/macosx/", System.getProperty("java.io.tmpdir") + File.separator);\r
-       }\r
-\r
-       private static void loadLibrary (String libName, String nativePath, String outputPath) {\r
-               if (new File(outputPath + libName).exists()) return;\r
-\r
-               InputStream in = null;\r
-               BufferedOutputStream out = null;\r
-\r
-               try {\r
-                       in = LwjglApplication.class.getResourceAsStream(nativePath + libName);\r
-                       out = new BufferedOutputStream(new FileOutputStream(outputPath + libName));\r
-                       byte[] bytes = new byte[1024 * 4];\r
-                       while (true) {\r
-                               int read_bytes = in.read(bytes);\r
-                               if (read_bytes == -1) break;\r
-\r
-                               out.write(bytes, 0, read_bytes);\r
-                       }\r
-                       out.close();\r
-                       out = null;\r
-                       in.close();\r
-                       in = null;\r
-               } catch (Throwable t) {\r
-                       // throw new GdxRuntimeException("Couldn't load lwjgl native, " + libName, t);\r
-               } finally {\r
-                       if (out != null) try {\r
-                               out.close();\r
-                       } catch (Exception ex) {\r
-                       }\r
-                       ;\r
-                       if (in != null) try {\r
-                               in.close();\r
-                       } catch (Exception ex) {\r
-                       }\r
+               if (isWindows) {\r
+                       extractLibrary("OpenAL32.dll", "OpenAL64.dll");\r
+                       extractLibrary("lwjgl.dll", "lwjgl64.dll");\r
+               } else if (isMac) {\r
+                       extractLibrary("openal.dylib", "openal.dylib");\r
+                       extractLibrary("liblwjgl.jnilib", "liblwjgl.jnilib");\r
+               } else if (isLinux) {\r
+                       extractLibrary("libopenal.so", "libopenal64.so");\r
+                       extractLibrary("liblwjgl.so", "liblwjgl64.so");\r
                }\r
+               System.setProperty("org.lwjgl.librarypath", nativesDir.getAbsolutePath());\r
+               load = false;\r
        }\r
-\r
 }\r
index 83762e2..dda1047 100644 (file)
@@ -23,6 +23,7 @@ import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.Graphics;\r
 import com.badlogic.gdx.Input;\r
 import com.badlogic.gdx.Version;\r
+import com.badlogic.gdx.utils.GdxNativesLoader;\r
 \r
 public class AngleApplication implements Application, ESLoop {\r
        AngleGraphics graphics;\r
@@ -37,7 +38,7 @@ public class AngleApplication implements Application, ESLoop {
                final boolean fullscreen) {\r
                new Thread(new Runnable() {\r
                        public void run () {\r
-                               Version.loadLibrary();\r
+                               GdxNativesLoader.load();\r
 \r
                                AngleApplication.this.listener = listener;\r
                                utils = new ESUtil(title, width, height, ESUtil.ES_WINDOW_DEPTH | (fullscreen ? ESUtil.ES_WINDOW_FULLSCREEN : 0));\r
index 09cfbb2..a9ed063 100644 (file)
@@ -26,6 +26,7 @@ import com.badlogic.gdx.files.FileHandle;
 import com.badlogic.gdx.utils.Array;\r
 import com.badlogic.gdx.utils.GdxRuntimeException;\r
 import com.badlogic.gdx.utils.IntArray;\r
+import com.badlogic.gdx.utils.ObjectMap;\r
 \r
 import static org.lwjgl.openal.AL10.*;\r
 \r
@@ -34,6 +35,8 @@ import static org.lwjgl.openal.AL10.*;
  */\r
 public class OpenALAudio implements Audio {\r
        private int[] streams;\r
+       private ObjectMap<String, Class<? extends OpenALSound>> extensionToSoundClass = new ObjectMap();\r
+       private ObjectMap<String, Class<? extends OpenALMusic>> extensionToMusicClass = new ObjectMap();\r
 \r
        Array<OpenALMusic> music = new Array(false, 1, OpenALMusic.class);\r
 \r
@@ -42,6 +45,13 @@ public class OpenALAudio implements Audio {
        }\r
 \r
        public OpenALAudio (int simultaneousStreams) {\r
+               registerSound("ogg", Ogg.Sound.class);\r
+               registerMusic("ogg", Ogg.Music.class);\r
+               registerSound("wav", Wav.Sound.class);\r
+               registerMusic("wav", Wav.Music.class);\r
+               registerSound("mp3", Mp3.Sound.class);\r
+               registerMusic("mp3", Mp3.Music.class);\r
+\r
                try {\r
                        AL.create();\r
                } catch (LWJGLException ex) {\r
@@ -65,28 +75,38 @@ public class OpenALAudio implements Audio {
                alListener(AL_POSITION, position);\r
        }\r
 \r
+       public void registerSound (String extension, Class<? extends OpenALSound> soundClass) {\r
+               if (extension == null) throw new IllegalArgumentException("extension cannot be null.");\r
+               if (soundClass == null) throw new IllegalArgumentException("soundClass cannot be null.");\r
+               extensionToSoundClass.put(extension, soundClass);\r
+       }\r
+\r
+       public void registerMusic (String extension, Class<? extends OpenALMusic> musicClass) {\r
+               if (extension == null) throw new IllegalArgumentException("extension cannot be null.");\r
+               if (musicClass == null) throw new IllegalArgumentException("musicClass cannot be null.");\r
+               extensionToMusicClass.put(extension, musicClass);\r
+       }\r
+\r
        public OpenALSound newSound (FileHandle file) {\r
-               String extension = file.extension();\r
-               if (extension.equals("ogg")) {\r
-                       return new Ogg.Sound(this, file);\r
-               } else if (extension.equals("mp3")) {\r
-                       return new Mp3.Sound(this, file);\r
-               } else if (extension.equals("wav")) {\r
-                       return new Wav.Sound(this, file);\r
+               if (file == null) throw new IllegalArgumentException("file cannot be null.");\r
+               Class<? extends OpenALSound> soundClass = extensionToSoundClass.get(file.extension());\r
+               if (soundClass == null) throw new GdxRuntimeException("Unknown file extension for sound: " + file);\r
+               try {\r
+                       return soundClass.getConstructor(new Class[] {OpenALAudio.class, FileHandle.class}).newInstance(this, file);\r
+               } catch (Exception ex) {\r
+                       throw new GdxRuntimeException("Error creating sound " + soundClass.getName() + " for file: " + file);\r
                }\r
-               throw new GdxRuntimeException("Unknown file extension for sound: " + file);\r
        }\r
 \r
        public OpenALMusic newMusic (FileHandle file) {\r
-               String extension = file.extension();\r
-               if (extension.equals("ogg")) {\r
-                       return new Ogg.Music(this, file);\r
-               } else if (extension.equals("mp3")) {\r
-                       return new Mp3.Music(this, file);\r
-               } else if (extension.equals("wav")) {\r
-                       return new Wav.Music(this, file);\r
+               if (file == null) throw new IllegalArgumentException("file cannot be null.");\r
+               Class<? extends OpenALMusic> musicClass = extensionToMusicClass.get(file.extension());\r
+               if (musicClass == null) throw new GdxRuntimeException("Unknown file extension for music: " + file);\r
+               try {\r
+                       return musicClass.getConstructor(new Class[] {OpenALAudio.class, FileHandle.class}).newInstance(this, file);\r
+               } catch (Exception ex) {\r
+                       throw new GdxRuntimeException("Error creating music " + musicClass.getName() + " for file: " + file);\r
                }\r
-               throw new GdxRuntimeException("Unknown file extension for music: " + file);\r
        }\r
 \r
        int getIdleStreamID () {\r
index a865d90..adb42f6 100644 (file)
@@ -24,19 +24,4 @@ import com.badlogic.gdx.utils.GdxNativesLoader;
 public class Version {\r
        /** the current version of libgdx in the major.minor format **/\r
        public static String VERSION = "0.81";\r
-\r
-       public static void loadLibrary () {             \r
-               String os = System.getProperty("os.name");\r
-               String arch = System.getProperty("os.arch");\r
-               String vm = System.getProperty("java.vm.name");\r
-               \r
-               if(!(vm != null && vm.contains("Dalvik")))\r
-                       if (GdxNativesLoader.loadLibraries()) return;\r
-\r
-               if (!arch.equals("amd64") || os.contains("Mac")) {\r
-                       System.loadLibrary("gdx");\r
-               } else {\r
-                       System.loadLibrary("gdx-64");\r
-               }\r
-       }\r
 }\r
index f24338e..d865f6c 100644 (file)
@@ -613,6 +613,12 @@ public class BitmapFont {
                this.scaleY = scaleY;\r
        }\r
 \r
+       /**\r
+        * Scales the font by the specified amount in both directions.<br>\r
+        * <br>\r
+        * Note that smoother scaling can be achieved if the texture backing the BitmapFont is using {@link TextureFilter#Linear}. The\r
+        * default is Nearest, so use a BitmapFont constructor that takes a {@link TextureRegion}.\r
+        */\r
        public void setScale (float scaleXY) {\r
                setScale(scaleXY, scaleXY);\r
        }\r
index 959b605..30f0e11 100644 (file)
@@ -16,92 +16,74 @@ package com.badlogic.gdx.utils;
 import java.io.BufferedOutputStream;\r
 import java.io.File;\r
 import java.io.FileOutputStream;\r
+import java.io.IOException;\r
 import java.io.InputStream;\r
 \r
+import com.badlogic.gdx.Version;\r
+\r
 public class GdxNativesLoader {\r
-       static boolean nativesLoaded = false;\r
+       static private boolean nativesLoaded = false;\r
 \r
-       /**\r
-        * loads the necessary libraries depending on the operating system\r
-        */\r
-       public static boolean loadLibraries () {\r
-               if (nativesLoaded) return true;\r
-               String os = System.getProperty("os.name");\r
-               String arch = System.getProperty("os.arch");\r
-               boolean is64Bit = false;\r
+       static public boolean isWindows = System.getProperty("os.name").contains("Windows");\r
+       static public boolean isLinux = System.getProperty("os.name").contains("Linux");\r
+       static public boolean isMac = System.getProperty("os.name").contains("Mac");\r
+       static public boolean is64Bit = System.getProperty("os.arch").equals("amd64");\r
+       static public File nativesDir = new File(System.getProperty("java.io.tmpdir") + "/libgdx/" + Version.VERSION);\r
 \r
-               if (arch.equals("amd64")) is64Bit = true;\r
+       static public boolean loadLibrary (String nativeFile32, String nativeFile64) {\r
+               String path = extractLibrary(nativeFile32, nativeFile64);\r
+               if (path != null) System.load(path);\r
+               return path != null;\r
+       }\r
 \r
-               String prefix = getLibraryPrefix();\r
-               String suffix = getLibrarySuffix();\r
-               String libName = prefix + "gdx" + (is64Bit ? "-64" : "") + suffix;\r
-               if (!loadLibrary(libName, "/", System.getProperty("java.io.tmpdir") + File.separator)) {\r
-                       return false;\r
-               } else {\r
-                       nativesLoaded = true;\r
-                       return true;\r
+       static public String extractLibrary (String native32, String native64) {\r
+               try {\r
+                       // Extract native from classpath to temp dir.\r
+                       String nativeFileName = is64Bit ? native64 : native32;\r
+                       InputStream input = GdxNativesLoader.class.getResourceAsStream("/" + nativeFileName);\r
+                       if (input == null) return null;\r
+                       nativesDir.mkdirs();\r
+                       File nativeFile = new File(nativesDir, nativeFileName);\r
+                       FileOutputStream output = new FileOutputStream(nativeFile);\r
+                       byte[] buffer = new byte[4096];\r
+                       while (true) {\r
+                               int length = input.read(buffer);\r
+                               if (length == -1) break;\r
+                               output.write(buffer, 0, length);\r
+                       }\r
+                       input.close();\r
+                       output.close();\r
+                       return nativeFile.getAbsolutePath();\r
+               } catch (IOException ex) {\r
+                       ex.printStackTrace();\r
+                       return null;\r
                }\r
        }\r
 \r
-       public static String getLibraryPrefix () {\r
-               String os = System.getProperty("os.name");\r
-\r
-               if (os.contains("Windows"))\r
-                       return "";\r
-               else\r
-                       return "lib";\r
-       }\r
+       /**\r
+        * Loads the libgdx native libraries.\r
+        */\r
+       static public void load () {\r
+               if (nativesLoaded) return;\r
 \r
-       public static String getLibrarySuffix () {\r
-               String os = System.getProperty("os.name");\r
-               if (os.contains("Windows")) return ".dll";\r
-               if (os.contains("Linux")) return ".so";\r
-               if (os.contains("Mac")) return ".dylib";\r
-               return "";\r
-       }\r
+               String vm = System.getProperty("java.vm.name");\r
+               if (vm == null || !vm.contains("Dalvik")) {\r
+                       if (isWindows) {\r
+                               nativesLoaded = loadLibrary("gdx.dll", "gdx64.dll");\r
+                       } else if (isMac) {\r
+                               nativesLoaded = loadLibrary("libgdx.dylib", "libgdx.dylib");\r
+                       } else if (isLinux) {\r
+                               nativesLoaded = loadLibrary("libgdx.so", "libgdx-64.so");\r
+                       }\r
+                       if (nativesLoaded) return;\r
+               }\r
 \r
-       public static boolean is64Bit () {\r
                String arch = System.getProperty("os.arch");\r
-               return arch.toLowerCase().contains("amd64");\r
-       }\r
-\r
-       public static boolean loadLibrary (String libName, String classPath, String outputPath) {\r
-// if (new File(outputPath + libName).exists())\r
-// return true;\r
-\r
-               InputStream in = null;\r
-               BufferedOutputStream out = null;\r
-\r
-               try {\r
-                       String tmpName = System.nanoTime() + libName;\r
-                       in = GdxNativesLoader.class.getResourceAsStream(classPath + libName);\r
-                       out = new BufferedOutputStream(new FileOutputStream(outputPath + tmpName));\r
-                       byte[] bytes = new byte[1024 * 4];\r
-                       while (true) {\r
-                               int read_bytes = in.read(bytes);\r
-                               if (read_bytes == -1) break;\r
-\r
-                               out.write(bytes, 0, read_bytes);\r
-                       }\r
-                       out.close();\r
-                       out = null;\r
-                       in.close();\r
-                       in = null;\r
-                       System.load(outputPath + tmpName);\r
-                       return true;\r
-               } catch (Throwable t) {\r
-                       //System.err.println("GdxNativesLoader: Couldn't unpack and load native '" + libName + "'");\r
-                       return false;\r
-               } finally {\r
-                       if (out != null) try {\r
-                               out.close();\r
-                       } catch (Exception ex) {\r
-                       }\r
-                       ;\r
-                       if (in != null) try {\r
-                               in.close();\r
-                       } catch (Exception ex) {\r
-                       }\r
+               String os = System.getProperty("os.name");\r
+               if (!arch.equals("amd64") || os.contains("Mac")) {\r
+                       System.loadLibrary("gdx");\r
+               } else {\r
+                       System.loadLibrary("gdx-64");\r
                }\r
        }\r
 }\r