com.badlogic.gdx.utils.SharedLibraryLoader Java Examples

The following examples show how to use com.badlogic.gdx.utils.SharedLibraryLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KTXProcessor.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
protected File copyToTempFile(String resourcePath) {
    File file = super.copyToTempFile(resourcePath);
    if (file == null) return null;

    if (SharedLibraryLoader.isLinux || SharedLibraryLoader.isMac) {
        try {
            // Change access permission for temp file
            System.out.println("Call \"chmod\" for a temp file");
            Process process = Runtime.getRuntime().exec("chmod +x " + file.getAbsolutePath());

            InputStream is = process.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
            int result = process.waitFor(); // Let the process finish.

            if (result != 0) {
                throw new RuntimeException("\"chmod\" call finished with error");
            }
        } catch (IOException | InterruptedException e) {
            throw new RuntimeException("Error changing file access permission for: " + file.getAbsolutePath(), e);
        }
    }
    return file;
}
 
Example #2
Source File: KtxEtc2Processor.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
protected File copyToTempFile(String resourcePath) {
    File file = super.copyToTempFile(resourcePath);
    if (file == null) return null;

    if (SharedLibraryLoader.isLinux || SharedLibraryLoader.isMac) {
        try {
            // Change access permission for temp file
            System.out.println("Call \"chmod\" for a temp file");
            Process process = Runtime.getRuntime().exec("chmod +x " + file.getAbsolutePath());

            InputStream is = process.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
            int result = process.waitFor(); // Let the process finish.

            if (result != 0) {
                throw new RuntimeException("\"chmod\" call finished with error");
            }
        } catch (IOException | InterruptedException e) {
            throw new RuntimeException("Error changing file access permission for: " + file.getAbsolutePath(), e);
        }
    }
    return file;
}
 
Example #3
Source File: Lwjgl3Mini2DxWindow.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
static void setIcon(long windowHandle, String[] imagePaths, Files.FileType imageFileType) {
	if (SharedLibraryLoader.isMac)
		return;

	Pixmap[] pixmaps = new Pixmap[imagePaths.length];
	for (int i = 0; i < imagePaths.length; i++) {
		pixmaps[i] = new Pixmap(Gdx.files.getFileHandle(imagePaths[i], imageFileType));
	}

	setIcon(windowHandle, pixmaps);

	for (Pixmap pixmap : pixmaps) {
		pixmap.dispose();
	}
}
 
Example #4
Source File: FreeType.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
public static Library initFreeType() {
	new SharedLibraryLoader().load("gdx-freetype");
	long address = initFreeTypeJni();
	if(address == 0) throw new GdxRuntimeException("Couldn't initialize FreeType library, FreeType error code: " + getLastErrorCode());
	else return new Library(address);
}
 
Example #5
Source File: SoundTouch.java    From gameserver with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new SoundTouch object. Needs to be disposed via {@link #dispose()}.
 */
public SoundTouch() {
	new SharedLibraryLoader().load("gdx-audio");
	addr = newSoundTouchJni();
}
 
Example #6
Source File: KissFFT.java    From gameserver with Apache License 2.0 4 votes vote down vote up
/** Creates a new fft instance that can analyse numSamples samples. timeSize must be a power of two.
 * 
 * @param numSamples the number of samples to be analysed. */
public KissFFT (int numSamples) {
	new SharedLibraryLoader().load("gdx-audio");
	addr = create(numSamples);
}
 
Example #7
Source File: DesktopLaunchValidator.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public static boolean verifyValidJVMState(String[] args){

		//mac computers require the -XstartOnFirstThread JVM argument
		if (SharedLibraryLoader.isMac){

			// If XstartOnFirstThread is present and enabled, we can return true
			if ("1".equals(System.getenv("JAVA_STARTED_ON_FIRST_THREAD_" +
					ManagementFactory.getRuntimeMXBean().getName().split("@")[0]))) {
				return true;
			}

			// Check if we are the relaunched process, if so return true to avoid looping.
			// The game will likely crash, but that's unavoidable at this point.
			if ("true".equals(System.getProperty("shpdRelaunched"))){
				System.err.println("Error: Could not verify new process is running on the first thread. Trying to run the game anyway...");
				return true;
			}

			// Relaunch a new jvm process with the same arguments, plus -XstartOnFirstThread
			String sep = System.getProperty("file.separator");

			ArrayList<String> jvmArgs = new ArrayList<>();
			jvmArgs.add(System.getProperty("java.home") + sep + "bin" + sep + "java");
			jvmArgs.add("-XstartOnFirstThread");
			jvmArgs.add("-DshpdRelaunched=true");
			jvmArgs.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments());
			jvmArgs.add("-cp");
			jvmArgs.add(System.getProperty("java.class.path"));
			jvmArgs.add(DesktopLauncher.class.getName());

			System.err.println("Error: ShatteredPD must start on the first thread in order to work on macOS.");
			System.err.println("  To avoid this error, run the game with the \"-XstartOnFirstThread\" argument");
			System.err.println("  Now attempting to relaunch the game on the first thread automatically:\n");

			try {
				Process process = new ProcessBuilder(jvmArgs).redirectErrorStream(true).start();
				BufferedReader out = new BufferedReader(new InputStreamReader(process.getInputStream()));
				String line;

				//Relay console output from the relaunched process
				while ((line = out.readLine()) != null) {
					if (line.toLowerCase().startsWith("error")){
						System.err.println(line);
					} else {
						System.out.println(line);
					}
				}

				process.waitFor();
			} catch (Exception e) {
				e.printStackTrace();
			}

			return false;

		}

		return true;
	}
 
Example #8
Source File: DesktopLauncher.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public static void main (String[] args) {

		if (!DesktopLaunchValidator.verifyValidJVMState(args)){
			return;
		}
		
		final String title;
		if (DesktopLauncher.class.getPackage().getSpecificationTitle() == null){
			title = System.getProperty("Specification-Title");
		} else {
			title = DesktopLauncher.class.getPackage().getSpecificationTitle();
		}
		
		Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
			@Override
			public void uncaughtException(Thread thread, Throwable throwable) {
				Game.reportException(throwable);
				StringWriter sw = new StringWriter();
				PrintWriter pw = new PrintWriter(sw);
				throwable.printStackTrace(pw);
				pw.flush();
				String exceptionMsg = sw.toString();

				//shorten/simplify exception message to make it easier to fit into a message box
				exceptionMsg = exceptionMsg.replaceAll("\\(.*:([0-9]*)\\)", "($1)");
				exceptionMsg = exceptionMsg.replace("com.shatteredpixel.shatteredpixeldungeon.", "");
				exceptionMsg = exceptionMsg.replace("com.watabou.", "");
				exceptionMsg = exceptionMsg.replace("com.badlogic.gdx.", "");
				exceptionMsg = exceptionMsg.replace("\t", "    ");

				TinyFileDialogs.tinyfd_messageBox(title + " Has Crashed!",
						title + " has run into an error it can't recover from and has crashed, sorry about that!\n\n" +
						"If you could, please email this error message to the developer ([email protected]):\n\n" +
						"version: " + Game.version + "\n" +
						exceptionMsg,
						"ok", "error", false );
				if (Gdx.app != null) Gdx.app.exit();
			}
		});
		
		Game.version = DesktopLauncher.class.getPackage().getSpecificationVersion();
		if (Game.version == null) {
			Game.version = System.getProperty("Specification-Version");
		}
		
		try {
			Game.versionCode = Integer.parseInt(DesktopLauncher.class.getPackage().getImplementationVersion());
		} catch (NumberFormatException e) {
			Game.versionCode = Integer.parseInt(System.getProperty("Implementation-Version"));
		}

		if (UpdateImpl.supportsUpdates()){
			Updates.service = UpdateImpl.getUpdateService();
		}
		
		Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
		
		config.setTitle( title );
		
		String basePath = "";
		if (SharedLibraryLoader.isWindows) {
			if (System.getProperties().getProperty("os.name").equals("Windows XP")) {
				basePath = "Application Data/.shatteredpixel/Shattered Pixel Dungeon/";
			} else {
				basePath = "AppData/Roaming/.shatteredpixel/Shattered Pixel Dungeon/";
			}
		} else if (SharedLibraryLoader.isMac) {
			basePath = "Library/Application Support/Shattered Pixel Dungeon/";
		} else if (SharedLibraryLoader.isLinux) {
			basePath = ".shatteredpixel/shattered-pixel-dungeon/";
		}

		//copy over prefs from old file location from legacy desktop codebase
		FileHandle oldPrefs = new Lwjgl3FileHandle(basePath + "pd-prefs", Files.FileType.External);
		FileHandle newPrefs = new Lwjgl3FileHandle(basePath + SPDSettings.DEFAULT_PREFS_FILE, Files.FileType.External);
		if (oldPrefs.exists() && !newPrefs.exists()){
			oldPrefs.copyTo(newPrefs);
		}

		config.setPreferencesConfig( basePath, Files.FileType.External );
		SPDSettings.set( new Lwjgl3Preferences( SPDSettings.DEFAULT_PREFS_FILE, basePath) );
		FileUtils.setDefaultFileProperties( Files.FileType.External, basePath );
		
		config.setWindowSizeLimits( 480, 320, -1, -1 );
		Point p = SPDSettings.windowResolution();
		config.setWindowedMode( p.x, p.y );
		config.setAutoIconify( true );
		
		//we set fullscreen/maximized in the listener as doing it through the config seems to be buggy
		DesktopWindowListener listener = new DesktopWindowListener();
		config.setWindowListener( listener );
		
		config.setWindowIcon("icons/icon_16.png", "icons/icon_32.png", "icons/icon_64.png",
				"icons/icon_128.png", "icons/icon_256.png");

		new Lwjgl3Application(new ShatteredPixelDungeon(new DesktopPlatformSupport()), config);
	}
 
Example #9
Source File: DesktopLauncher.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
public static void main (String[] arg) {
	String version = DesktopLauncher.class.getPackage().getSpecificationVersion();
	if (version == null) {
		version = "0.7.5f";
	}

	int versionCode;
	try {
		versionCode = Integer.parseInt(DesktopLauncher.class.getPackage().getImplementationVersion());
	} catch (NumberFormatException e) {
		versionCode = 383;
	}

	LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();

	if (SharedLibraryLoader.isMac) {
		config.preferencesDirectory = "Library/Application Support/Shattered Pixel Dungeon/";
	} else if (SharedLibraryLoader.isLinux) {
		config.preferencesDirectory = ".shatteredpixel/shattered-pixel-dungeon/";
	} else if (SharedLibraryLoader.isWindows) {
		String winVer = System.getProperties().getProperty("os.name");
		if (winVer.contains("XP")) {
			config.preferencesDirectory = "Application Data/.shatteredpixel/Shattered Pixel Dungeon/";
		} else {
			config.preferencesDirectory = "AppData/Roaming/.shatteredpixel/Shattered Pixel Dungeon/";
		}
	}
	// FIXME: This is a hack to get access to the preferences before we have an application setup
	com.badlogic.gdx.Preferences prefs = new LwjglPreferences(SPDSettings.FILE_NAME, config.preferencesDirectory);

	boolean isFullscreen = prefs.getBoolean(SPDSettings.KEY_WINDOW_FULLSCREEN, false);
	//config.fullscreen = isFullscreen;
	if (!isFullscreen) {
		config.width = prefs.getInteger(SPDSettings.KEY_WINDOW_WIDTH, SPDSettings.DEFAULT_WINDOW_WIDTH);
		config.height = prefs.getInteger(SPDSettings.KEY_WINDOW_HEIGHT, SPDSettings.DEFAULT_WINDOW_HEIGHT);
	}

	config.addIcon( "ic_launcher_128.png", Files.FileType.Internal );
	config.addIcon( "ic_launcher_32.png", Files.FileType.Internal );
	config.addIcon( "ic_launcher_16.png", Files.FileType.Internal );

	// TODO: It have to be pulled from build.gradle, but I don't know how it can be done
	config.title = "Shattered Pixel Dungeon";

	new LwjglApplication(new ShatteredPixelDungeon(
			new DesktopSupport(version, versionCode, config.preferencesDirectory, new DesktopInputProcessor())
	), config);
}
 
Example #10
Source File: DesktopLauncher.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isFullscreenEnabled() {
//	return Display.getPixelScaleFactor() == 1f;
	return !SharedLibraryLoader.isMac;
}