Skip to content

Commit 4cf6200

Browse files
committed
Add --console option to the launcher
The --console option shows the GUI console even in headless mode. Launcher version bumped to v1.8.11.
1 parent 891c7b1 commit 4cf6200

File tree

6 files changed

+90
-52
lines changed

6 files changed

+90
-52
lines changed

ChangeLog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
1.3.7 - TBD
22

3+
* Launcher v1.8.11: added --console option to show the GUI console even in
4+
headless mode.
35
* Added player entity rendering.
46
* Added option to disable player loading in the General tab in the
57
Render Controls window.

chunky/src/java/se/llbit/chunky/main/CommandLineOptions.java

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import se.llbit.json.JsonString;
4545
import se.llbit.json.JsonValue;
4646
import se.llbit.util.MCDownloader;
47+
import se.llbit.util.StringUtil;
4748

4849
public class CommandLineOptions {
4950
enum Mode {
@@ -56,41 +57,42 @@ enum Mode {
5657
/**
5758
* The help string
5859
*/
59-
private static final String USAGE =
60-
"Usage: chunky [OPTIONS] [WORLD DIRECTORY]\n" +
61-
"Options:\n" +
62-
" -texture <FILE> use FILE as the texture pack (must be a Zip file)\n" +
63-
" -render <SCENE> render the specified scene (see notes)\n" +
64-
" -snapshot <SCENE> [PNG] create a snapshot of the specified scene\n" +
65-
" -scene-dir <DIR> use the directory DIR for loading/saving scenes\n" +
66-
" -benchmark run the benchmark and exit\n" +
67-
" -threads <NUM> use the specified number of threads for rendering\n" +
68-
" -tile-width <NUM> use the specified job tile width\n" +
69-
" -target <NUM> override target SPP to be NUM in headless mode\n" +
70-
" -opencl enables OpenCL rendering in the GUI\n" +
71-
" -set <NAME> <VALUE> set a global configuration option and exit\n" +
72-
" -reset <NAME> reset a global configuration option and exit\n" +
73-
" -set <NAME> <VALUE> <SCENE>\n" +
74-
" set a configuration option for a scene and exit\n" +
75-
" -reset <NAME> <SCENE> reset a configuration option for a scene and exit\n" +
76-
" -reset <NAME> <SCENE> reset a configuration option for a scene and exit\n" +
77-
" -download-mc <VERSION> download the given Minecraft version and exit\n" +
78-
" -help show this text\n" +
79-
"\n" +
80-
"Notes:\n" +
81-
"<SCENE> can be either the path to a Scene Description File (" + SceneDescription.SCENE_DESCRIPTION_EXTENSION + "),\n" +
82-
"*OR* the name of a scene relative to the scene directory (excluding extension).\n" +
83-
"If the scene name is an absolute path then the scene directory will be the\n" +
84-
"parent directory of the Scene Description File, otherwise the scene directory\n" +
85-
"can be overridden temporarily by the -scene-dir option.\n" +
86-
"\n" +
87-
"Launcher options:\n" +
88-
" --update download the latest version of Chunky and exit\n" +
89-
" --setup configure memory limit and Java options for Chunky\n" +
90-
" --nolauncher start Chunky as normal, but without opening launcher\n" +
91-
" --launcher forces the launcher window to be displayed\n" +
92-
" --version print the launcher version and exit\n" +
93-
" --verbose verbose logging in the launcher\n";
60+
private static final String USAGE = StringUtil.join("\n",
61+
"Usage: chunky [OPTIONS] [WORLD DIRECTORY]",
62+
"Options:",
63+
" -texture <FILE> use FILE as the texture pack (must be a Zip file)",
64+
" -render <SCENE> render the specified scene (see notes)",
65+
" -snapshot <SCENE> [PNG] create a snapshot of the specified scene",
66+
" -scene-dir <DIR> use the directory DIR for loading/saving scenes",
67+
" -benchmark run the benchmark and exit",
68+
" -threads <NUM> use the specified number of threads for rendering",
69+
" -tile-width <NUM> use the specified job tile width",
70+
" -target <NUM> override target SPP to be NUM in headless mode",
71+
" -opencl enables OpenCL rendering in the GUI",
72+
" -set <NAME> <VALUE> set a global configuration option and exit",
73+
" -reset <NAME> reset a global configuration option and exit",
74+
" -set <NAME> <VALUE> <SCENE>",
75+
" set a configuration option for a scene and exit",
76+
" -reset <NAME> <SCENE> reset a configuration option for a scene and exit",
77+
" -reset <NAME> <SCENE> reset a configuration option for a scene and exit",
78+
" -download-mc <VERSION> download the given Minecraft version and exit",
79+
" -help show this text",
80+
"",
81+
"Notes:",
82+
"<SCENE> can be either the path to a Scene Description File (" + SceneDescription.SCENE_DESCRIPTION_EXTENSION + "),",
83+
"*OR* the name of a scene relative to the scene directory (excluding extension).",
84+
"If the scene name is an absolute path then the scene directory will be the",
85+
"parent directory of the Scene Description File, otherwise the scene directory",
86+
"can be overridden temporarily by the -scene-dir option.",
87+
"",
88+
"Launcher options:",
89+
" --update download the latest version of Chunky and exit",
90+
" --setup configure memory limit and Java options for Chunky",
91+
" --nolauncher start Chunky as normal, but without opening launcher",
92+
" --launcher forces the launcher window to be displayed",
93+
" --version print the launcher version and exit",
94+
" --verbose verbose logging in the launcher",
95+
" --console show the GUI console in headless mode");
9496

9597
protected boolean confError = false;
9698

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* Copyright (c) 2015 Jesper Öqvist <jesper@llbit.se>
2+
*
3+
* This file is part of Chunky.
4+
*
5+
* Chunky is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* Chunky is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
* You should have received a copy of the GNU General Public License
15+
* along with Chunky. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
package se.llbit.util;
18+
19+
public abstract class StringUtil {
20+
/** Join the string arguments using a separator string. */
21+
public static String join(String separator, String... strings) {
22+
StringBuilder buf = new StringBuilder();
23+
for (int i = 0; i < strings.length; ++i) {
24+
if (i > 0) {
25+
buf.append(separator);
26+
}
27+
buf.append(strings[i]);
28+
}
29+
return buf.toString();
30+
}
31+
}

launcher/src/se/llbit/chunky/launcher/ChunkyDeployer.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static boolean checkVersionIntegrity(String version) {
6363
return false;
6464
}
6565

66-
// check version
66+
// Check version.
6767
try {
6868
FileInputStream in = new FileInputStream(versionFile);
6969
JsonParser parser = new JsonParser(in);
@@ -160,7 +160,7 @@ private static void deployEmbeddedVersion(VersionInfo version) {
160160

161161
ClassLoader parentCL = ChunkyLauncher.class.getClassLoader();
162162

163-
// deploy libraries that were not already installed correctly
163+
// Deploy libraries that were not already installed correctly.
164164
for (Library lib: version.libraries) {
165165
if (lib.testIntegrity(libDir) != LibraryStatus.PASSED) {
166166
unpackLibrary(parentCL, "lib/" + lib.name,
@@ -236,7 +236,7 @@ public int launchChunky(Component parentComponent, LauncherSettings settings, Ve
236236
}
237237
ProcessBuilder procBuilder = new ProcessBuilder(command);
238238
final Logger logger;
239-
if (!settings.headless && settings.debugConsole) {
239+
if (settings.forceGuiConsole || (!settings.headless && settings.debugConsole)) {
240240
DebugConsole console = new DebugConsole(null, settings.closeConsoleOnExit);
241241
console.setVisible(true);
242242
logger = console;
@@ -248,7 +248,7 @@ public int launchChunky(Component parentComponent, LauncherSettings settings, Ve
248248
Runtime.getRuntime().addShutdownHook(new Thread() {
249249
@Override
250250
public void run() {
251-
// kill the subprocess
251+
// Kill the subprocess.
252252
proc.destroy();
253253
}
254254
});
@@ -300,30 +300,31 @@ public void run() {
300300
shutdownThread.start();
301301
try {
302302
if (mode == ChunkyMode.GUI) {
303-
// just wait a little while to check for startup errors
303+
// Just wait a little while to check for startup errors.
304304
Thread.sleep(3000);
305305
return shutdownThread.exitValue;
306306
} else {
307-
// wait until completion so we can return correct exit code
307+
// Wait until completion so we can return correct exit code.
308308
return shutdownThread.exitValue();
309309
}
310310
} catch (InterruptedException e) {
311311
}
312312
return 0;
313313
} catch (IOException e) {
314314
logger.appendErrorLine(e.getMessage());
315-
// 3 indicates launcher error
315+
// TODO(jesper): Add constant for this return value.
316+
// Exit code 3 indicates launcher error.
316317
return 3;
317318
}
318319
}
319320

320321
/**
321-
* @param command
322+
* Convert a command in list form to string.
322323
* @return command in string form
323324
*/
324325
public static String commandString(List<String> command) {
325326
StringBuilder sb = new StringBuilder();
326-
for (String part: command) {
327+
for (String part : command) {
327328
if (sb.length() > 0) {
328329
sb.append(" ");
329330
}
@@ -339,7 +340,7 @@ public static List<String> buildCommandLine(VersionInfo version, LauncherSetting
339340
cmd.add("-Xmx" + settings.memoryLimit + "m");
340341

341342
String[] parts = settings.javaOptions.split(" ");
342-
for (String part: parts) {
343+
for (String part : parts) {
343344
if (!part.isEmpty()) {
344345
cmd.add(part);
345346
}
@@ -355,7 +356,7 @@ public static List<String> buildCommandLine(VersionInfo version, LauncherSetting
355356
cmd.add("se.llbit.chunky.main.Chunky");
356357

357358
parts = settings.chunkyOptions.split(" ");
358-
for (String part: parts) {
359+
for (String part : parts) {
359360
if (!part.isEmpty()) {
360361
cmd.add(part);
361362
}
@@ -368,7 +369,7 @@ private static String classpath(VersionInfo version, LauncherSettings settings)
368369
File chunkyDir = PersistentSettings.getSettingsDirectory();
369370
File libDir = new File(chunkyDir, "lib");
370371
List<File> jars = new ArrayList<File>();
371-
for (VersionInfo.Library library: version.libraries) {
372+
for (VersionInfo.Library library : version.libraries) {
372373
jars.add(library.getFile(libDir));
373374
}
374375
String classpath = "";
@@ -429,7 +430,7 @@ public void run() {
429430
public static VersionInfo resolveVersion(String name) {
430431
List<VersionInfo> versions = availableVersions();
431432
VersionInfo version = VersionInfo.LATEST;
432-
for (VersionInfo info: versions) {
433+
for (VersionInfo info : versions) {
433434
if (info.name.equals(name)) {
434435
version = info;
435436
break;
@@ -448,7 +449,7 @@ public static VersionInfo resolveVersion(String name) {
448449

449450
public static boolean canLaunch(VersionInfo version, ChunkyLauncher launcher, boolean reportErrors) {
450451
if (version == VersionInfo.NONE) {
451-
// version not available!
452+
// Version not available!
452453
System.err.println("No version installed");
453454
if (reportErrors) {
454455
Dialogs.error(launcher,

launcher/src/se/llbit/chunky/launcher/ChunkyLauncher.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
@SuppressWarnings("serial")
5959
public class ChunkyLauncher extends JFrame implements UpdateListener {
6060

61-
private static final String LAUNCHER_VERSION = "v1.8.10";
61+
private static final String LAUNCHER_VERSION = "v1.8.11";
6262

6363
protected String java;
6464
private final ChunkyDeployer deployer;
@@ -563,8 +563,7 @@ public static void main(String[] args) {
563563
final LauncherSettings settings = new LauncherSettings();
564564
settings.load();
565565

566-
/*
567-
* If there are command line arguments then we assume that Chunky should run
566+
/* If there are command line arguments then we assume that Chunky should run
568567
* in headless mode, unless the --nolauncher command is present in which case
569568
* we strip that and start regularly, but without launcher. The --launcher
570569
* option overrides everything else and forces the launcher to appear.
@@ -586,6 +585,8 @@ public static void main(String[] args) {
586585
return;
587586
} else if (arg.equals("--verbose")) {
588587
settings.verboseLauncher = true;
588+
} else if (arg.equals("--console")) {
589+
settings.forceGuiConsole = true;
589590
} else if (arg.equals("--update") || arg.equals("--updateAlpha")) {
590591
if (arg.equals("--updateAlpha")) {
591592
System.out.println("Checking for Chunky alpha/snapshot updates..");

lib/src/se/llbit/chunky/launcher/LauncherSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class LauncherSettings {
2828
public String javaDir = "";
2929
public int memoryLimit = DEFAULT_MEMORY_LIMIT;
3030
public boolean debugConsole = false;
31+
public boolean forceGuiConsole = false;
3132
public boolean verboseLogging = false;
3233
public boolean verboseLauncher = false;
3334
public String javaOptions = "";

0 commit comments

Comments
 (0)