mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 04:41:51 +09:00
error trap to inform players wtf went wrong
This commit is contained in:
@@ -291,67 +291,78 @@ public class App implements ApplicationListener {
|
||||
System.out.println(csiG+TerrarumAppConfiguration.COPYRIGHT_LICENSE_TERMS_SHORT+csi0);
|
||||
|
||||
|
||||
// load configs
|
||||
getDefaultDirectory();
|
||||
createDirs();
|
||||
readConfigJson();
|
||||
updateListOfSavegames();
|
||||
|
||||
setGamepadButtonLabels();
|
||||
try {
|
||||
|
||||
|
||||
try { processor = GetCpuName.getModelName(); }
|
||||
catch (IOException e1) { processor = "Unknown CPU"; }
|
||||
try { processorVendor = GetCpuName.getCPUID(); }
|
||||
catch (IOException e2) { processorVendor = "Unknown CPU"; }
|
||||
// load configs
|
||||
getDefaultDirectory();
|
||||
createDirs();
|
||||
readConfigJson();
|
||||
updateListOfSavegames();
|
||||
|
||||
setGamepadButtonLabels();
|
||||
|
||||
|
||||
ShaderProgram.pedantic = false;
|
||||
|
||||
scr = new TerrarumScreenSize(getConfigInt("screenwidth"), getConfigInt("screenheight"));
|
||||
int width = scr.getWidth();
|
||||
int height = scr.getHeight();
|
||||
|
||||
Lwjgl3ApplicationConfiguration appConfig = new Lwjgl3ApplicationConfiguration();
|
||||
//appConfig.useGL30 = false; // https://stackoverflow.com/questions/46753218/libgdx-should-i-use-gl30
|
||||
appConfig.useVsync(getConfigBoolean("usevsync"));
|
||||
appConfig.setResizable(false);
|
||||
appConfig.setWindowedMode(width, height);
|
||||
int fps = Math.min(GLOBAL_FRAMERATE_LIMIT, getConfigInt("displayfps"));
|
||||
if (fps <= 0) fps = GLOBAL_FRAMERATE_LIMIT;
|
||||
appConfig.setIdleFPS(fps);
|
||||
appConfig.setForegroundFPS(fps);
|
||||
appConfig.setTitle(GAME_NAME);
|
||||
//appConfig.forceExit = true; // it seems KDE 5 likes this one better...
|
||||
// (Plasma freezes upon app exit. with forceExit = true, it's only frozen for a minute; with forceExit = false, it's indefinite)
|
||||
//appConfig.samples = 4; // force the AA on, if the graphics driver didn't do already
|
||||
|
||||
// load app icon
|
||||
int[] appIconSizes = new int[]{256,128,64,32,16};
|
||||
ArrayList<String> appIconPaths = new ArrayList<>();
|
||||
for (int size : appIconSizes) {
|
||||
String name = "assets/appicon" + size + ".png";
|
||||
if (new File("./" + name).exists()) {
|
||||
appIconPaths.add("./" + name);
|
||||
try {
|
||||
processor = GetCpuName.getModelName();
|
||||
}
|
||||
catch (IOException e1) {
|
||||
processor = "Unknown CPU";
|
||||
}
|
||||
try {
|
||||
processorVendor = GetCpuName.getCPUID();
|
||||
}
|
||||
catch (IOException e2) {
|
||||
processorVendor = "Unknown CPU";
|
||||
}
|
||||
}
|
||||
|
||||
Object[] iconPathsTemp = appIconPaths.toArray();
|
||||
appConfig.setWindowIcon(Arrays.copyOf(iconPathsTemp, iconPathsTemp.length, String[].class));
|
||||
|
||||
//if (args.length == 1 && args[0].equals("isdev=true")) {
|
||||
ShaderProgram.pedantic = false;
|
||||
|
||||
scr = new TerrarumScreenSize(getConfigInt("screenwidth"), getConfigInt("screenheight"));
|
||||
int width = scr.getWidth();
|
||||
int height = scr.getHeight();
|
||||
|
||||
Lwjgl3ApplicationConfiguration appConfig = new Lwjgl3ApplicationConfiguration();
|
||||
//appConfig.useGL30 = false; // https://stackoverflow.com/questions/46753218/libgdx-should-i-use-gl30
|
||||
appConfig.useVsync(getConfigBoolean("usevsync"));
|
||||
appConfig.setResizable(false);
|
||||
appConfig.setWindowedMode(width, height);
|
||||
int fps = Math.min(GLOBAL_FRAMERATE_LIMIT, getConfigInt("displayfps"));
|
||||
if (fps <= 0) fps = GLOBAL_FRAMERATE_LIMIT;
|
||||
appConfig.setIdleFPS(fps);
|
||||
appConfig.setForegroundFPS(fps);
|
||||
appConfig.setTitle(GAME_NAME);
|
||||
//appConfig.forceExit = true; // it seems KDE 5 likes this one better...
|
||||
// (Plasma freezes upon app exit. with forceExit = true, it's only frozen for a minute; with forceExit = false, it's indefinite)
|
||||
//appConfig.samples = 4; // force the AA on, if the graphics driver didn't do already
|
||||
|
||||
// load app icon
|
||||
int[] appIconSizes = new int[]{256, 128, 64, 32, 16};
|
||||
ArrayList<String> appIconPaths = new ArrayList<>();
|
||||
for (int size : appIconSizes) {
|
||||
String name = "assets/appicon" + size + ".png";
|
||||
if (new File("./" + name).exists()) {
|
||||
appIconPaths.add("./" + name);
|
||||
}
|
||||
}
|
||||
|
||||
Object[] iconPathsTemp = appIconPaths.toArray();
|
||||
appConfig.setWindowIcon(Arrays.copyOf(iconPathsTemp, iconPathsTemp.length, String[].class));
|
||||
|
||||
IS_DEVELOPMENT_BUILD = true;
|
||||
// safe area box
|
||||
//KeyToggler.INSTANCE.forceSet(Input.Keys.F11, true);
|
||||
//}
|
||||
//else {
|
||||
// System.err.println("Game not started using DEBUG MODE -- current build of the game will display black screen without debug mode");
|
||||
//}
|
||||
|
||||
// set some more configuration vars
|
||||
MULTITHREAD = THREAD_COUNT >= 3 && getConfigBoolean("multithread");
|
||||
|
||||
new Lwjgl3Application(new App(appConfig), appConfig);
|
||||
// set some more configuration vars
|
||||
MULTITHREAD = THREAD_COUNT >= 3 && getConfigBoolean("multithread");
|
||||
|
||||
new Lwjgl3Application(new App(appConfig), appConfig);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
if (Gdx.app != null) {
|
||||
Gdx.app.exit();
|
||||
}
|
||||
new GameCrashHandler(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
66
src/net/torvald/terrarum/GameCrashHandler.kt
Normal file
66
src/net/torvald/terrarum/GameCrashHandler.kt
Normal file
@@ -0,0 +1,66 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Color
|
||||
import java.awt.Dimension
|
||||
import java.awt.Font
|
||||
import java.awt.Font.BOLD
|
||||
import java.awt.Font.PLAIN
|
||||
import java.io.OutputStream
|
||||
import java.io.PrintStream
|
||||
import javax.swing.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-09-18.
|
||||
*/
|
||||
class GameCrashHandler(e: Throwable) : JFrame() {
|
||||
|
||||
val textArea = JTextArea()
|
||||
|
||||
private val outputStream = object : OutputStream() {
|
||||
override fun write(p0: Int) {
|
||||
textArea.append("${p0.toChar()}")
|
||||
}
|
||||
}
|
||||
|
||||
private val printStream = object : PrintStream(outputStream) {}
|
||||
|
||||
init {
|
||||
val border = JPanel()
|
||||
border.layout = BorderLayout(18,18)
|
||||
border.isVisible = true
|
||||
border.background = Color(63,79,93)
|
||||
|
||||
|
||||
val title = JLabel("Help! A blackhole ate my game!")
|
||||
title.font = Font("SansSerif", BOLD, 18)
|
||||
title.foreground = Color.WHITE
|
||||
title.isVisible = true
|
||||
title.horizontalAlignment = SwingConstants.CENTER
|
||||
border.add(title, BorderLayout.NORTH)
|
||||
|
||||
|
||||
textArea.font = Font("Monospaced", PLAIN, 14)
|
||||
textArea.isVisible = true
|
||||
textArea.isEditable = false
|
||||
border.add(JScrollPane(textArea), BorderLayout.CENTER)
|
||||
|
||||
|
||||
this.layout = BorderLayout(32,32)
|
||||
this.size = Dimension(1280, 720)
|
||||
this.isVisible = true
|
||||
this.defaultCloseOperation = EXIT_ON_CLOSE
|
||||
this.contentPane.background = Color(63,79,93)
|
||||
this.add(JLabel(), BorderLayout.EAST)
|
||||
this.add(JLabel(), BorderLayout.WEST)
|
||||
this.add(JLabel(), BorderLayout.SOUTH)
|
||||
this.add(JLabel(), BorderLayout.NORTH)
|
||||
this.add(border, BorderLayout.CENTER)
|
||||
this.title = TerrarumAppConfiguration.GAME_NAME
|
||||
|
||||
|
||||
e.printStackTrace(printStream)
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -213,7 +213,7 @@ open class GameWorld() : Disposable {
|
||||
return tileNumberToNameMap[layerWall.unsafeGetTile(x, y).toLong()]!!
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
val msg = "No tile name mapping for wall ${layerWall.unsafeGetTile(x, y)} in ($x, $y)"
|
||||
val msg = "No tile name mapping for wall ${layerWall.unsafeGetTile(x, y)} in ($x, $y) from $layerWall"
|
||||
throw NoSuchElementException(msg)
|
||||
}
|
||||
}
|
||||
@@ -228,7 +228,7 @@ open class GameWorld() : Disposable {
|
||||
return tileNumberToNameMap[layerTerrain.unsafeGetTile(x, y).toLong()]!!
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
val msg = "No tile name mapping for terrain ${layerTerrain.unsafeGetTile(x, y)} in ($x, $y)"
|
||||
val msg = "No tile name mapping for terrain ${layerTerrain.unsafeGetTile(x, y)} in ($x, $y) from $layerTerrain"
|
||||
throw NoSuchElementException(msg)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user