Skip to content

Commit

Permalink
Prep for 0.3.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesTKhan committed Jun 7, 2022
1 parent 7b6a9df commit 4ea43e2
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 5 deletions.
2 changes: 1 addition & 1 deletion commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: "java"
apply plugin: "maven-publish"

group = 'com.github.jpooleycodes.mundus'
version = '0.3.0'
version = '0.3.1'

sourceCompatibility = 1.7
targetCompatibility = 1.7
Expand Down
3 changes: 2 additions & 1 deletion editor/CHANGES
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[0.3.1] ~ TBD
[0.3.1] ~ 07/06/2022
- Added functionality to the editor to generate the assets.txt file, PR #45
- Added Ambient Light and Directional Light to Environment menu
- Fix NPE in editor when creating new terrain
- Fix NPE on model placement
- Fix Wave speed increasing exponentially based on water tile count
- Fix Fog now applies to water
- Add StartOnFirstThread helper to resolve launching on Mac

[0.3.0] ~ 17/05/2022
- Added GLB support, PR #21
Expand Down
2 changes: 1 addition & 1 deletion editor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ task run(dependsOn: classes, type: JavaExec) {

task distEditor(type: Jar) {
archivesBaseName = 'Mundus'
archiveVersion.set('0.3.0')
archiveVersion.set('0.3.1')

duplicatesStrategy(DuplicatesStrategy.EXCLUDE)

Expand Down
6 changes: 5 additions & 1 deletion editor/src/main/com/mbrlabs/mundus/editor/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.kotcrab.vis.ui.util.OsUtils
import com.mbrlabs.mundus.editor.utils.Log
import com.mbrlabs.mundus.editor.utils.StartOnFirstThreadHelper

const private val TAG = "Main"
const val TITLE = "Mundus v0.3.0"
const val TITLE = "Mundus v0.3.1"

fun main(arg: Array<String>) {
// Temporary fix for MacOS, we should be able to remove when we update libGDX to 1.11.0 and use
// gdx-lwjgl3-glfw-awt-macos extension instead https://libgdx.com/news/2022/05/gdx-1-11
StartOnFirstThreadHelper.startNewJvmIfRequired()
Log.init()
launchEditor()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* 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:
* 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.mbrlabs.mundus.editor.utils;

import com.badlogic.gdx.scenes.scene2d.utils.UIUtils;
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.
*
* @author damios
* @see <a href=
* "http://www.java-gaming.org/topics/starting-jvm-on-mac-with-xstartonfirstthread-programmatically/37697/view.html">Based
* on http://www.java-gaming.org/topics/-/37697/view.html</a>
*
*/
public class StartOnFirstThreadHelper {

private static final String JVM_RESTARTED_ARG = "jvmIsRestarted";

private StartOnFirstThreadHelper() {
throw new UnsupportedOperationException();
}

/**
* 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.
* <p>
* <u>Usage:</u>
*
* <pre>
* public static void main(String... args) {
* if (StartOnFirstThreadHelper.startNewJvmIfRequired()) {
* return; // don't execute any code
* }
* // the actual main method code
* }
* </pre>
*
* @param redirectOutput whether the output of the new JVM should be rerouted to
* the new 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) {
if (!UIUtils.isMac) {
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>();
String separator = System.getProperty("file.separator");
// TODO Java 9: ProcessHandle.current().info().command();
String javaExecPath = System.getProperty("java.home") + separator + "bin" + separator + "java";
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"));
jvmArgs.add(System.getenv("JAVA_MAIN_CLASS_" + pid));

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 (StartOnFirstThreadHelper.startNewJvmIfRequired()) {
* return; // don't execute any code
* }
* // 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 required; otherwise executes the main method code given
* as Runnable. When used with lambdas, this is allows for less verbose code
* than {@link #startNewJvmIfRequired()}:
*
* <pre>
* public static void main(String... args) {
* StartOnFirstThreadHelper.executeIfJVMValid(() -> {
* // the actual main method code
* });
* }
* </pre>
*
* @param mainMethodCode
*/
public static void executeIfJVMValid(Runnable mainMethodCode) {
if (startNewJvmIfRequired()) {
return;
}
mainMethodCode.run();
}

}
2 changes: 1 addition & 1 deletion gdx-runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: "java"
apply plugin: "maven-publish"

group = 'com.github.jpooleycodes.mundus'
version = '0.3.0'
version = '0.3.1'

sourceCompatibility = 1.7
targetCompatibility = 1.7
Expand Down

0 comments on commit 4ea43e2

Please sign in to comment.