aboutsummaryrefslogtreecommitdiff
path: root/lwjgl3/src
diff options
context:
space:
mode:
Diffstat (limited to 'lwjgl3/src')
-rw-r--r--lwjgl3/src/main/java/coffee/liz/abstractionengine/lwjgl3/Lwjgl3Launcher.java92
-rw-r--r--lwjgl3/src/main/java/coffee/liz/abstractionengine/lwjgl3/StartupHelper.java310
2 files changed, 201 insertions, 201 deletions
diff --git a/lwjgl3/src/main/java/coffee/liz/abstractionengine/lwjgl3/Lwjgl3Launcher.java b/lwjgl3/src/main/java/coffee/liz/abstractionengine/lwjgl3/Lwjgl3Launcher.java
index 21b4a23..ee7e19f 100644
--- a/lwjgl3/src/main/java/coffee/liz/abstractionengine/lwjgl3/Lwjgl3Launcher.java
+++ b/lwjgl3/src/main/java/coffee/liz/abstractionengine/lwjgl3/Lwjgl3Launcher.java
@@ -8,56 +8,56 @@ import com.badlogic.gdx.graphics.glutils.HdpiMode;
/** Launches the desktop (LWJGL3) application. */
public class Lwjgl3Launcher {
- public static void main(final String[] args) {
- if (StartupHelper.startNewJvmIfRequired())
- return; // This handles macOS support and helps on Windows.
- createApplication();
- }
+ public static void main(final String[] args) {
+ if (StartupHelper.startNewJvmIfRequired())
+ return; // This handles macOS support and helps on Windows.
+ createApplication();
+ }
- private static Lwjgl3Application createApplication() {
- return new Lwjgl3Application(new AbstractionEngineGame(), getDefaultConfiguration());
- }
+ private static Lwjgl3Application createApplication() {
+ return new Lwjgl3Application(new AbstractionEngineGame(), getDefaultConfiguration());
+ }
- private static Lwjgl3ApplicationConfiguration getDefaultConfiguration() {
- final Lwjgl3ApplicationConfiguration configuration = new Lwjgl3ApplicationConfiguration();
- configuration.setTitle("The Abstraction Engine");
- //// Vsync limits the frames per second to what your hardware can display, and
- //// helps eliminate
- //// screen tearing. This setting doesn't always work on Linux, so the line
- //// after is a safeguard.
- configuration.useVsync(true);
- //// Limits FPS to the refresh rate of the currently active monitor, plus 1 to
- //// try to match fractional
- //// refresh rates. The Vsync setting above should limit the actual FPS to match
- //// the monitor.
- configuration.setForegroundFPS(Lwjgl3ApplicationConfiguration.getDisplayMode().refreshRate + 1);
- //// If you remove the above line and set Vsync to false, you can get unlimited
- //// FPS, which can be
- //// useful for testing performance, but can also be very stressful to some
- //// hardware.
- //// You may also need to configure GPU drivers to fully disable Vsync; this can
- //// cause screen tearing.
+ private static Lwjgl3ApplicationConfiguration getDefaultConfiguration() {
+ final Lwjgl3ApplicationConfiguration configuration = new Lwjgl3ApplicationConfiguration();
+ configuration.setTitle("The Abstraction Engine");
+ //// Vsync limits the frames per second to what your hardware can display, and
+ //// helps eliminate
+ //// screen tearing. This setting doesn't always work on Linux, so the line
+ //// after is a safeguard.
+ configuration.useVsync(true);
+ //// Limits FPS to the refresh rate of the currently active monitor, plus 1 to
+ //// try to match fractional
+ //// refresh rates. The Vsync setting above should limit the actual FPS to match
+ //// the monitor.
+ configuration.setForegroundFPS(Lwjgl3ApplicationConfiguration.getDisplayMode().refreshRate + 1);
+ //// If you remove the above line and set Vsync to false, you can get unlimited
+ //// FPS, which can be
+ //// useful for testing performance, but can also be very stressful to some
+ //// hardware.
+ //// You may also need to configure GPU drivers to fully disable Vsync; this can
+ //// cause screen tearing.
- configuration.setHdpiMode(HdpiMode.Logical);
+ configuration.setHdpiMode(HdpiMode.Logical);
- configuration.setWindowedMode(1024, 1024);
- configuration.setDecorated(false);
- //// You can change these files; they are in lwjgl3/src/main/resources/ .
- //// They can also be loaded from the root of assets/ .
- configuration.setWindowIcon("libgdx128.png", "libgdx64.png", "libgdx32.png", "libgdx16.png");
+ configuration.setWindowedMode(1024, 1024);
+ configuration.setDecorated(false);
+ //// You can change these files; they are in lwjgl3/src/main/resources/ .
+ //// They can also be loaded from the root of assets/ .
+ configuration.setWindowIcon("libgdx128.png", "libgdx64.png", "libgdx32.png", "libgdx16.png");
- //// This should improve compatibility with Windows machines with buggy OpenGL
- //// drivers, Macs
- //// with Apple Silicon that have to emulate compatibility with OpenGL anyway,
- //// and more.
- //// This uses the dependency `com.badlogicgames.gdx:gdx-lwjgl3-angle` to
- //// function.
- //// You can choose to remove the following line and the mentioned dependency if
- //// you want; they
- //// are not intended for games that use GL30 (which is compatibility with
- //// OpenGL ES 3.0).
- configuration.setOpenGLEmulation(Lwjgl3ApplicationConfiguration.GLEmulation.ANGLE_GLES20, 0, 0);
+ //// This should improve compatibility with Windows machines with buggy OpenGL
+ //// drivers, Macs
+ //// with Apple Silicon that have to emulate compatibility with OpenGL anyway,
+ //// and more.
+ //// This uses the dependency `com.badlogicgames.gdx:gdx-lwjgl3-angle` to
+ //// function.
+ //// You can choose to remove the following line and the mentioned dependency if
+ //// you want; they
+ //// are not intended for games that use GL30 (which is compatibility with
+ //// OpenGL ES 3.0).
+ configuration.setOpenGLEmulation(Lwjgl3ApplicationConfiguration.GLEmulation.ANGLE_GLES20, 0, 0);
- return configuration;
- }
+ return configuration;
+ }
}
diff --git a/lwjgl3/src/main/java/coffee/liz/abstractionengine/lwjgl3/StartupHelper.java b/lwjgl3/src/main/java/coffee/liz/abstractionengine/lwjgl3/StartupHelper.java
index 21520f9..9e49b68 100644
--- a/lwjgl3/src/main/java/coffee/liz/abstractionengine/lwjgl3/StartupHelper.java
+++ b/lwjgl3/src/main/java/coffee/liz/abstractionengine/lwjgl3/StartupHelper.java
@@ -45,174 +45,174 @@ import static org.lwjgl.system.macosx.ObjCRuntime.sel_getUid;
*/
public class StartupHelper {
- private static final String JVM_RESTARTED_ARG = "jvmIsRestarted";
+ private static final String JVM_RESTARTED_ARG = "jvmIsRestarted";
- private StartupHelper() {
- throw new UnsupportedOperationException();
- }
+ private StartupHelper() {
+ throw new UnsupportedOperationException();
+ }
- /**
- * Starts a new JVM if the application was started on macOS without the
- * {@code -XstartOnFirstThread} argument. This also includes some code for
- * Windows, for the case where the user's home directory includes certain
- * non-Latin-alphabet characters (without this code, most LWJGL3 apps fail
- * immediately for those users). Returns whether a new JVM was started and thus
- * no code should be executed.
- * <p>
- * <u>Usage:</u>
- *
- * <pre>
- * <code>
- * public static void main(String... args) {
- * if (StartupHelper.startNewJvmIfRequired(true)) return; // This handles macOS support and helps on Windows.
- * // after this is the actual main method code
- * }
- * </code>
- * </pre>
- *
- * @param redirectOutput
- * whether the output of the new JVM should be rerouted to the old
- * JVM, so it can be accessed in the same place; keeps the old JVM
- * running if enabled
- * @return whether a new JVM was started and thus no code should be executed in
- * this one
- */
- public static boolean startNewJvmIfRequired(boolean redirectOutput) {
- String osName = System.getProperty("os.name").toLowerCase(java.util.Locale.ROOT);
- if (!osName.contains("mac")) {
- if (osName.contains("windows")) {
- // Here, we are trying to work around an issue with how LWJGL3 loads its
- // extracted .dll files.
- // By default, LWJGL3 extracts to the directory specified by "java.io.tmpdir",
- // which is usually the user's home.
- // If the user's name has non-ASCII (or some non-alphanumeric) characters in it,
- // that would fail.
- // By extracting to the relevant "ProgramData" folder, which is usually
- // "C:\ProgramData", we avoid this.
- // We also temporarily change the "user.name" property to one without any chars
- // that would be invalid.
- // We revert our changes immediately after loading LWJGL3 natives.
- String programData = System.getenv("ProgramData");
- if (programData == null)
- programData = "C:\\Temp\\"; // if ProgramData isn't set, try some fallback.
- String prevTmpDir = System.getProperty("java.io.tmpdir", programData);
- String prevUser = System.getProperty("user.name", "libGDX_User");
- System.setProperty("java.io.tmpdir", programData + "/libGDX-temp");
- System.setProperty("user.name",
- ("User_" + prevUser.hashCode() + "_GDX" + Version.VERSION).replace('.', '_'));
- Lwjgl3NativesLoader.load();
- System.setProperty("java.io.tmpdir", prevTmpDir);
- System.setProperty("user.name", prevUser);
- }
- return false;
- }
+ /**
+ * Starts a new JVM if the application was started on macOS without the
+ * {@code -XstartOnFirstThread} argument. This also includes some code for
+ * Windows, for the case where the user's home directory includes certain
+ * non-Latin-alphabet characters (without this code, most LWJGL3 apps fail
+ * immediately for those users). Returns whether a new JVM was started and thus
+ * no code should be executed.
+ * <p>
+ * <u>Usage:</u>
+ *
+ * <pre>
+ * <code>
+ * public static void main(String... args) {
+ * if (StartupHelper.startNewJvmIfRequired(true)) return; // This handles macOS support and helps on Windows.
+ * // after this is the actual main method code
+ * }
+ * </code>
+ * </pre>
+ *
+ * @param redirectOutput
+ * whether the output of the new JVM should be rerouted to the old
+ * JVM, so it can be accessed in the same place; keeps the old JVM
+ * running if enabled
+ * @return whether a new JVM was started and thus no code should be executed in
+ * this one
+ */
+ public static boolean startNewJvmIfRequired(boolean redirectOutput) {
+ String osName = System.getProperty("os.name").toLowerCase(java.util.Locale.ROOT);
+ if (!osName.contains("mac")) {
+ if (osName.contains("windows")) {
+ // Here, we are trying to work around an issue with how LWJGL3 loads its
+ // extracted .dll files.
+ // By default, LWJGL3 extracts to the directory specified by "java.io.tmpdir",
+ // which is usually the user's home.
+ // If the user's name has non-ASCII (or some non-alphanumeric) characters in it,
+ // that would fail.
+ // By extracting to the relevant "ProgramData" folder, which is usually
+ // "C:\ProgramData", we avoid this.
+ // We also temporarily change the "user.name" property to one without any chars
+ // that would be invalid.
+ // We revert our changes immediately after loading LWJGL3 natives.
+ String programData = System.getenv("ProgramData");
+ if (programData == null)
+ programData = "C:\\Temp\\"; // if ProgramData isn't set, try some fallback.
+ String prevTmpDir = System.getProperty("java.io.tmpdir", programData);
+ String prevUser = System.getProperty("user.name", "libGDX_User");
+ System.setProperty("java.io.tmpdir", programData + "/libGDX-temp");
+ System.setProperty("user.name",
+ ("User_" + prevUser.hashCode() + "_GDX" + Version.VERSION).replace('.', '_'));
+ Lwjgl3NativesLoader.load();
+ System.setProperty("java.io.tmpdir", prevTmpDir);
+ System.setProperty("user.name", prevUser);
+ }
+ return false;
+ }
- // There is no need for -XstartOnFirstThread on Graal native image
- if (!System.getProperty("org.graalvm.nativeimage.imagecode", "").isEmpty()) {
- return false;
- }
+ // There is no need for -XstartOnFirstThread on Graal native image
+ if (!System.getProperty("org.graalvm.nativeimage.imagecode", "").isEmpty()) {
+ return false;
+ }
- // Checks if we are already on the main thread, such as from running via
- // Construo.
- long objc_msgSend = ObjCRuntime.getLibrary().getFunctionAddress("objc_msgSend");
- long NSThread = objc_getClass("NSThread");
- long currentThread = invokePPP(NSThread, sel_getUid("currentThread"), objc_msgSend);
- boolean isMainThread = invokePPZ(currentThread, sel_getUid("isMainThread"), objc_msgSend);
- if (isMainThread)
- return false;
+ // Checks if we are already on the main thread, such as from running via
+ // Construo.
+ long objc_msgSend = ObjCRuntime.getLibrary().getFunctionAddress("objc_msgSend");
+ long NSThread = objc_getClass("NSThread");
+ long currentThread = invokePPP(NSThread, sel_getUid("currentThread"), objc_msgSend);
+ boolean isMainThread = invokePPZ(currentThread, sel_getUid("isMainThread"), objc_msgSend);
+ if (isMainThread)
+ return false;
- long pid = LibC.getpid();
+ long pid = LibC.getpid();
- // check whether -XstartOnFirstThread is enabled
- if ("1".equals(System.getenv("JAVA_STARTED_ON_FIRST_THREAD_" + pid))) {
- return false;
- }
+ // check whether -XstartOnFirstThread is enabled
+ if ("1".equals(System.getenv("JAVA_STARTED_ON_FIRST_THREAD_" + pid))) {
+ return false;
+ }
- // check whether the JVM was previously restarted
- // avoids looping, but most certainly leads to a crash
- if ("true".equals(System.getProperty(JVM_RESTARTED_ARG))) {
- System.err.println(
- "There was a problem evaluating whether the JVM was started with the -XstartOnFirstThread argument.");
- return false;
- }
+ // check whether the JVM was previously restarted
+ // avoids looping, but most certainly leads to a crash
+ if ("true".equals(System.getProperty(JVM_RESTARTED_ARG))) {
+ System.err.println(
+ "There was a problem evaluating whether the JVM was started with the -XstartOnFirstThread argument.");
+ return false;
+ }
- // Restart the JVM with -XstartOnFirstThread
- ArrayList<String> jvmArgs = new ArrayList<>();
- String separator = System.getProperty("file.separator", "/");
- // The following line is used assuming you target Java 8, the minimum for
- // LWJGL3.
- String javaExecPath = System.getProperty("java.home") + separator + "bin" + separator + "java";
- // If targeting Java 9 or higher, you could use the following instead of the
- // above line:
- // String javaExecPath = ProcessHandle.current().info().command().orElseThrow();
+ // Restart the JVM with -XstartOnFirstThread
+ ArrayList<String> jvmArgs = new ArrayList<>();
+ String separator = System.getProperty("file.separator", "/");
+ // The following line is used assuming you target Java 8, the minimum for
+ // LWJGL3.
+ String javaExecPath = System.getProperty("java.home") + separator + "bin" + separator + "java";
+ // If targeting Java 9 or higher, you could use the following instead of the
+ // above line:
+ // String javaExecPath = ProcessHandle.current().info().command().orElseThrow();
- if (!(new File(javaExecPath)).exists()) {
- System.err.println(
- "A Java installation could not be found. If you are distributing this app with a bundled JRE, be sure to set the -XstartOnFirstThread argument manually!");
- return false;
- }
+ if (!(new File(javaExecPath)).exists()) {
+ System.err.println(
+ "A Java installation could not be found. If you are distributing this app with a bundled JRE, be sure to set the -XstartOnFirstThread argument manually!");
+ return false;
+ }
- jvmArgs.add(javaExecPath);
- jvmArgs.add("-XstartOnFirstThread");
- jvmArgs.add("-D" + JVM_RESTARTED_ARG + "=true");
- jvmArgs.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments());
- jvmArgs.add("-cp");
- jvmArgs.add(System.getProperty("java.class.path"));
- String mainClass = System.getenv("JAVA_MAIN_CLASS_" + pid);
- if (mainClass == null) {
- StackTraceElement[] trace = Thread.currentThread().getStackTrace();
- if (trace.length > 0) {
- mainClass = trace[trace.length - 1].getClassName();
- } else {
- System.err.println("The main class could not be determined.");
- return false;
- }
- }
- jvmArgs.add(mainClass);
+ jvmArgs.add(javaExecPath);
+ jvmArgs.add("-XstartOnFirstThread");
+ jvmArgs.add("-D" + JVM_RESTARTED_ARG + "=true");
+ jvmArgs.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments());
+ jvmArgs.add("-cp");
+ jvmArgs.add(System.getProperty("java.class.path"));
+ String mainClass = System.getenv("JAVA_MAIN_CLASS_" + pid);
+ if (mainClass == null) {
+ StackTraceElement[] trace = Thread.currentThread().getStackTrace();
+ if (trace.length > 0) {
+ mainClass = trace[trace.length - 1].getClassName();
+ } else {
+ System.err.println("The main class could not be determined.");
+ return false;
+ }
+ }
+ jvmArgs.add(mainClass);
- try {
- if (!redirectOutput) {
- ProcessBuilder processBuilder = new ProcessBuilder(jvmArgs);
- processBuilder.start();
- } else {
- Process process = (new ProcessBuilder(jvmArgs)).redirectErrorStream(true).start();
- BufferedReader processOutput = new BufferedReader(new InputStreamReader(process.getInputStream()));
- String line;
+ try {
+ if (!redirectOutput) {
+ ProcessBuilder processBuilder = new ProcessBuilder(jvmArgs);
+ processBuilder.start();
+ } else {
+ Process process = (new ProcessBuilder(jvmArgs)).redirectErrorStream(true).start();
+ BufferedReader processOutput = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ String line;
- while ((line = processOutput.readLine()) != null) {
- System.out.println(line);
- }
+ while ((line = processOutput.readLine()) != null) {
+ System.out.println(line);
+ }
- process.waitFor();
- }
- } catch (Exception e) {
- System.err.println("There was a problem restarting the JVM");
- e.printStackTrace();
- }
+ process.waitFor();
+ }
+ } catch (Exception e) {
+ System.err.println("There was a problem restarting the JVM");
+ e.printStackTrace();
+ }
- return true;
- }
+ return true;
+ }
- /**
- * Starts a new JVM if the application was started on macOS without the
- * {@code -XstartOnFirstThread} argument. Returns whether a new JVM was started
- * and thus no code should be executed. Redirects the output of the new JVM to
- * the old one.
- * <p>
- * <u>Usage:</u>
- *
- * <pre>
- * public static void main(String... args) {
- * if (StartupHelper.startNewJvmIfRequired())
- * return; // This handles macOS support and helps on Windows.
- * // the actual main method code
- * }
- * </pre>
- *
- * @return whether a new JVM was started and thus no code should be executed in
- * this one
- */
- public static boolean startNewJvmIfRequired() {
- return startNewJvmIfRequired(true);
- }
+ /**
+ * Starts a new JVM if the application was started on macOS without the
+ * {@code -XstartOnFirstThread} argument. Returns whether a new JVM was started
+ * and thus no code should be executed. Redirects the output of the new JVM to
+ * the old one.
+ * <p>
+ * <u>Usage:</u>
+ *
+ * <pre>
+ * public static void main(String... args) {
+ * if (StartupHelper.startNewJvmIfRequired())
+ * return; // This handles macOS support and helps on Windows.
+ * // the actual main method code
+ * }
+ * </pre>
+ *
+ * @return whether a new JVM was started and thus no code should be executed in
+ * this one
+ */
+ public static boolean startNewJvmIfRequired() {
+ return startNewJvmIfRequired(true);
+ }
} \ No newline at end of file