Package com.badlogic.gdx.backends.lwjgl

Source Code of com.badlogic.gdx.backends.lwjgl.LwjglNativesLoader

/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

package com.badlogic.gdx.backends.lwjgl;

import static com.badlogic.gdx.utils.SharedLibraryLoader.*;

import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.GdxNativesLoader;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.SharedLibraryLoader;

import java.io.File;
import java.lang.reflect.Method;

public final class LwjglNativesLoader {
  static public boolean load = true;

  static {
    System.setProperty("org.lwjgl.input.Mouse.allowNegativeMouseCoords", "true");

    // Don't extract natives if using JWS.
    try {
      Method method = Class.forName("javax.jnlp.ServiceManager").getDeclaredMethod("lookup", new Class[] {String.class});
      method.invoke(null, "javax.jnlp.PersistenceService");
      load = false;
    } catch (Throwable ex) {
      load = true;
    }
  }

  /** Extracts the LWJGL native libraries from the classpath and sets the "org.lwjgl.librarypath" system property. */
  static public void load () {
    GdxNativesLoader.load();
    if (GdxNativesLoader.disableNativesLoading) return;
    if (!load) return;

    SharedLibraryLoader loader = new SharedLibraryLoader();
    File nativesDir = null;
    try {
      if (isWindows) {
        nativesDir = loader.extractFile(is64Bit ? "lwjgl64.dll" : "lwjgl.dll", null).getParentFile();
        if (!LwjglApplicationConfiguration.disableAudio)
          loader.extractFile(is64Bit ? "OpenAL64.dll" : "OpenAL32.dll", nativesDir.getName());
      } else if (isMac) {
        File extractedFile = loader.extractFile("liblwjgl.jnilib", null);
        nativesDir = extractedFile.getParentFile();
        new FileHandle(extractedFile).copyTo(new FileHandle(new File(nativesDir, "liblwjgl.dylib")));
        if (!LwjglApplicationConfiguration.disableAudio) loader.extractFile("openal.dylib", nativesDir.getName());
      } else if (isLinux) {
        nativesDir = loader.extractFile(is64Bit ? "liblwjgl64.so" : "liblwjgl.so", null).getParentFile();
        if (!LwjglApplicationConfiguration.disableAudio)
          loader.extractFile(is64Bit ? "libopenal64.so" : "libopenal.so", nativesDir.getName());
      }
    } catch (Throwable ex) {
      throw new GdxRuntimeException("Unable to extract LWJGL natives.", ex);
    }
    System.setProperty("org.lwjgl.librarypath", nativesDir.getAbsolutePath());
    load = false;
  }
}
TOP

Related Classes of com.badlogic.gdx.backends.lwjgl.LwjglNativesLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.