Upgrade project to libgdx 1.12.1
This commit is contained in:
110
lwjgl3/build.gradle
Normal file
110
lwjgl3/build.gradle
Normal file
@@ -0,0 +1,110 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
dependencies {
|
||||
if(enableGraalNative == 'true') {
|
||||
classpath "org.graalvm.buildtools.native:org.graalvm.buildtools.native.gradle.plugin:0.9.28"
|
||||
}
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
id "io.github.fourlastor.construo" version "1.2.0"
|
||||
id "application"
|
||||
}
|
||||
|
||||
|
||||
import io.github.fourlastor.construo.Target
|
||||
|
||||
sourceSets.main.resources.srcDirs += [ rootProject.file('assets').path ]
|
||||
mainClassName = 'de.samdev.colorrunner.lwjgl3.Lwjgl3Launcher'
|
||||
application.setMainClass(mainClassName)
|
||||
eclipse.project.name = appName + '-lwjgl3'
|
||||
java.sourceCompatibility = 11
|
||||
java.targetCompatibility = 11
|
||||
|
||||
dependencies {
|
||||
implementation "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
|
||||
implementation "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
|
||||
implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
|
||||
implementation project(':core')
|
||||
}
|
||||
|
||||
def jarName = "${appName}-${version}.jar"
|
||||
def os = System.properties['os.name'].toLowerCase()
|
||||
|
||||
run {
|
||||
workingDir = rootProject.file('assets').path
|
||||
setIgnoreExitValue(true)
|
||||
|
||||
if (os.contains('mac')) jvmArgs += "-XstartOnFirstThread"
|
||||
}
|
||||
|
||||
jar {
|
||||
// sets the name of the .jar file this produces to the name of the game or app.
|
||||
archiveFileName.set(jarName)
|
||||
// using 'lib' instead of the default 'libs' appears to be needed by jpackageimage.
|
||||
destinationDirectory = file("${project.layout.buildDirectory.asFile.get().absolutePath}/lib")
|
||||
// the duplicatesStrategy matters starting in Gradle 7.0; this setting works.
|
||||
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
|
||||
dependsOn configurations.runtimeClasspath
|
||||
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||
// these "exclude" lines remove some unnecessary duplicate files in the output JAR.
|
||||
exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
|
||||
dependencies {
|
||||
exclude('META-INF/INDEX.LIST', 'META-INF/maven/**')
|
||||
}
|
||||
// setting the manifest makes the JAR runnable.
|
||||
manifest {
|
||||
attributes 'Main-Class': project.mainClassName
|
||||
}
|
||||
// this last step may help on some OSes that need extra instruction to make runnable JARs.
|
||||
doLast {
|
||||
file(archiveFile).setExecutable(true, false)
|
||||
}
|
||||
}
|
||||
|
||||
construo {
|
||||
// name of the executable
|
||||
name.set(appName)
|
||||
// human-readable name, used for example in the `.app` name for macOS
|
||||
humanName.set(appName)
|
||||
// Optional, defaults to project version
|
||||
version.set("0.0.0")
|
||||
|
||||
targets.configure {
|
||||
create("linuxX64", Target.Linux) {
|
||||
architecture.set(Target.Architecture.X86_64)
|
||||
jdkUrl.set("https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.11%2B9/OpenJDK17U-jdk_x64_linux_hotspot_17.0.11_9.tar.gz")
|
||||
}
|
||||
create("macM1", Target.MacOs) {
|
||||
architecture.set(Target.Architecture.AARCH64)
|
||||
jdkUrl.set("https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.11%2B9/OpenJDK17U-jdk_aarch64_mac_hotspot_17.0.11_9.tar.gz")
|
||||
// macOS needs an identifier
|
||||
identifier.set("i.should.be.changed.before.merge." + appName)
|
||||
// Optional: icon for macOS
|
||||
macIcon.set(project.file("icons/logo.icns"))
|
||||
}
|
||||
create("macX64", Target.MacOs) {
|
||||
architecture.set(Target.Architecture.X86_64)
|
||||
jdkUrl.set("https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.11%2B9/OpenJDK17U-jdk_x64_mac_hotspot_17.0.11_9.tar.gz")
|
||||
// macOS needs an identifier
|
||||
identifier.set("i.should.be.changed.before.merge." + appName)
|
||||
// Optional: icon for macOS
|
||||
macIcon.set(project.file("icons/logo.icns"))
|
||||
}
|
||||
create("winX64", Target.Windows) {
|
||||
architecture.set(Target.Architecture.X86_64)
|
||||
jdkUrl.set("https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.11%2B9/OpenJDK17U-jdk_x64_windows_hotspot_17.0.11_9.zip")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Equivalent to the jar task; here for compatibility with gdx-setup.
|
||||
tasks.register('dist') {
|
||||
dependsOn 'jar'
|
||||
}
|
||||
|
||||
if(enableGraalNative == 'true') {
|
||||
apply from: file("nativeimage.gradle")
|
||||
}
|
||||
BIN
lwjgl3/icons/logo.icns
Normal file
BIN
lwjgl3/icons/logo.icns
Normal file
Binary file not shown.
BIN
lwjgl3/icons/logo.ico
Normal file
BIN
lwjgl3/icons/logo.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
BIN
lwjgl3/icons/logo.png
Normal file
BIN
lwjgl3/icons/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.5 KiB |
63
lwjgl3/nativeimage.gradle
Normal file
63
lwjgl3/nativeimage.gradle
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
project(":lwjgl3") {
|
||||
apply plugin: "org.graalvm.buildtools.native"
|
||||
|
||||
dependencies {
|
||||
implementation "io.github.berstanio:gdx-svmhelper-backend-lwjgl3:$graalHelperVersion"
|
||||
implementation "io.github.berstanio:gdx-svmhelper-extension-box2d:$graalHelperVersion"
|
||||
}
|
||||
graalvmNative {
|
||||
binaries {
|
||||
main {
|
||||
imageName = appName
|
||||
mainClass = project.mainClassName
|
||||
requiredVersion = '23.0'
|
||||
buildArgs.add("-march=compatibility")
|
||||
jvmArgs.addAll("-Dfile.encoding=UTF8")
|
||||
sharedLibrary = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run {
|
||||
doNotTrackState("Running the app should not be affected by Graal.")
|
||||
}
|
||||
|
||||
// Modified from https://lyze.dev/2021/04/29/libGDX-Internal-Assets-List/ ; thanks again, Lyze!
|
||||
// This creates a resource-config.json file based on the contents of the assets folder (and the libGDX icons).
|
||||
// This file is used by Graal Native to embed those specific files.
|
||||
// This has to run before nativeCompile, so it runs at the start of an unrelated resource-handling command.
|
||||
generateResourcesConfigFile.doFirst {
|
||||
def assetsFolder = new File("${project.rootDir}/assets/")
|
||||
def lwjgl3 = project(':lwjgl3')
|
||||
def resFolder = new File("${lwjgl3.projectDir}/src/main/resources/META-INF/native-image/${lwjgl3.ext.appName}")
|
||||
resFolder.mkdirs()
|
||||
def resFile = new File(resFolder, "resource-config.json")
|
||||
resFile.delete()
|
||||
resFile.append(
|
||||
"""{
|
||||
"resources":{
|
||||
"includes":[
|
||||
{
|
||||
"pattern": ".*(""")
|
||||
// This adds every filename in the assets/ folder to a pattern that adds those files as resources.
|
||||
fileTree(assetsFolder).each {
|
||||
// The backslash-Q and backslash-E escape the start and end of a literal string, respectively.
|
||||
resFile.append("\\\\Q${it.name}\\\\E|")
|
||||
}
|
||||
// We also match all of the window icon images this way and the font files that are part of libGDX.
|
||||
resFile.append(
|
||||
"""libgdx.+\\\\.png|lsans.+)"
|
||||
}
|
||||
]},
|
||||
"bundles":[]
|
||||
}"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
project(":core") {
|
||||
dependencies {
|
||||
implementation "io.github.berstanio:gdx-svmhelper-annotations:$graalHelperVersion"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package de.samdev.colorrunner.lwjgl3;
|
||||
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||
import de.samdev.colorrunner.CRGame;
|
||||
|
||||
/** Launches the desktop (LWJGL3) application. */
|
||||
public class Lwjgl3Launcher {
|
||||
public static void main(String[] args) {
|
||||
if (StartupHelper.startNewJvmIfRequired()) return; // This handles macOS support and helps on Windows.
|
||||
createApplication();
|
||||
}
|
||||
|
||||
private static Lwjgl3Application createApplication() {
|
||||
return new Lwjgl3Application(new CRGame(), getDefaultConfiguration());
|
||||
}
|
||||
|
||||
private static Lwjgl3ApplicationConfiguration getDefaultConfiguration() {
|
||||
Lwjgl3ApplicationConfiguration configuration = new Lwjgl3ApplicationConfiguration();
|
||||
configuration.setTitle("ColorRunner");
|
||||
configuration.useVsync(true);
|
||||
//// Limits FPS to the refresh rate of the currently active monitor.
|
||||
configuration.setForegroundFPS(Lwjgl3ApplicationConfiguration.getDisplayMode().refreshRate);
|
||||
//// 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.setWindowedMode(640, 480);
|
||||
configuration.setWindowIcon("libgdx128.png", "libgdx64.png", "libgdx32.png", "libgdx16.png");
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright 2020 damios
|
||||
*
|
||||
* 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:
|
||||
* https://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.
|
||||
*/
|
||||
//Note, the above license and copyright applies to this file only.
|
||||
|
||||
package de.samdev.colorrunner.lwjgl3;
|
||||
|
||||
import org.lwjgl.system.macosx.LibC;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Adds some utilities to ensure that the JVM was started with the
|
||||
* {@code -XstartOnFirstThread} argument, which is required on macOS for LWJGL 3
|
||||
* to function. Also helps on Windows when users have names with characters from
|
||||
* outside the Latin alphabet, a common cause of startup crashes.
|
||||
* <br>
|
||||
* <a href="https://jvm-gaming.org/t/starting-jvm-on-mac-with-xstartonfirstthread-programmatically/57547">Based on this java-gaming.org post by kappa</a>
|
||||
* @author damios
|
||||
*/
|
||||
public class StartupHelper {
|
||||
|
||||
private static final String JVM_RESTARTED_ARG = "jvmIsRestarted";
|
||||
|
||||
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();
|
||||
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.
|
||||
System.setProperty("java.io.tmpdir", System.getenv("ProgramData") + "/libGDX-temp");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// There is no need for -XstartOnFirstThread on Graal native image
|
||||
if (!System.getProperty("org.graalvm.nativeimage.imagecode", "").isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
long pid = LibC.getpid();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
BIN
lwjgl3/src/main/resources/libgdx128.png
Normal file
BIN
lwjgl3/src/main/resources/libgdx128.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.5 KiB |
BIN
lwjgl3/src/main/resources/libgdx16.png
Normal file
BIN
lwjgl3/src/main/resources/libgdx16.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 879 B |
BIN
lwjgl3/src/main/resources/libgdx32.png
Normal file
BIN
lwjgl3/src/main/resources/libgdx32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
BIN
lwjgl3/src/main/resources/libgdx64.png
Normal file
BIN
lwjgl3/src/main/resources/libgdx64.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
Reference in New Issue
Block a user