--verbose (-v) flag, system info in log

v5stable
Ondřej Hruška 11 years ago
parent ed595b6857
commit 530aed3957
  1. 32
      src/mightypork/gamecore/core/BaseApp.java
  2. 4
      src/mightypork/gamecore/eventbus/EventBus.java
  3. 2
      src/mightypork/gamecore/logging/Log.java
  4. 4
      src/mightypork/gamecore/logging/writers/SimpleLog.java
  5. 10
      src/mightypork/gamecore/resources/BaseDeferredResource.java
  6. 8
      src/mightypork/gamecore/resources/audio/SoundSystem.java
  7. 8
      src/mightypork/gamecore/resources/fonts/impl/CachedFont.java
  8. 7
      src/mightypork/gamecore/resources/fonts/impl/DeferredFont.java
  9. 3
      src/mightypork/gamecore/resources/fonts/impl/DeferredFontNative.java
  10. 8
      src/mightypork/gamecore/util/files/FileUtils.java
  11. 4
      src/mightypork/gamecore/util/files/InstanceLock.java
  12. 9
      src/mightypork/gamecore/util/files/config/PropertyManager.java
  13. 16
      src/mightypork/rogue/Launcher.java
  14. 1
      src/mightypork/rogue/RogueApp.java
  15. 4
      src/mightypork/rogue/screens/select_world/WorldSlot.java
  16. 3
      src/mightypork/rogue/screens/story/ScreenStory.java
  17. 4
      src/mightypork/rogue/world/gen/WorldCreator.java
  18. 8
      src/mightypork/rogue/world/gen/rooms/DeadEndRoom.java

@ -133,6 +133,12 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
{ {
this.lockFile = lockFile; this.lockFile = lockFile;
} }
public void setLogLevel(Level logLevel)
{
this.logLevel = logLevel;
}
} }
// modules // modules
@ -168,8 +174,6 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
{ {
WorkDir.init(workdir); WorkDir.init(workdir);
Log.i("Using workdir: " + WorkDir.getWorkDir());
opt.sigleInstance = singleInstance; opt.sigleInstance = singleInstance;
} }
@ -222,9 +226,14 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
* Setup logging * Setup logging
*/ */
final LogWriter log = Log.create(opt.logFilePrefix, new File(WorkDir.getDir(opt.logDir), opt.logFilePrefix + ".log"), opt.logArchiveCount); final LogWriter log = Log.create(opt.logFilePrefix, new File(WorkDir.getDir(opt.logDir), opt.logFilePrefix + ".log"), opt.logArchiveCount);
log.setLevel(opt.logLevel);
Log.setMainLogger(log); Log.setMainLogger(log);
Log.setLevel(opt.logLevel);
Log.setSysoutLevel(opt.logLevel);
// connect slickutil to the logger
org.newdawn.slick.util.Log.setLogSystem(new SlickLogRedirector(log)); org.newdawn.slick.util.Log.setLogSystem(new SlickLogRedirector(log));
logSystemInfo();
Log.i("=== Starting initialization sequence ==="); Log.i("=== Starting initialization sequence ===");
@ -304,6 +313,21 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
} }
private void logSystemInfo()
{
String txt = "";
txt += "\n### SYSTEM INFO ###\n\n";
txt += " Platform ...... " + System.getProperty("os.name") + "\n";
txt += " Runtime ....... " + System.getProperty("java.runtime.name") + "\n";
txt += " Java .......... " + System.getProperty("java.version") + "\n";
txt += " Launch path ... " + System.getProperty("user.dir") + "\n";
txt += " Workdir ....... " + WorkDir.getWorkDir().getAbsolutePath() + "\n";
Log.i(txt);
}
protected void registerIonizables() protected void registerIonizables()
{ {
Ion.registerType(Coord.ION_MARK, Coord.class); Ion.registerType(Coord.ION_MARK, Coord.class);
@ -477,7 +501,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
getEventBus().send(new DestroyEvent()); getEventBus().send(new DestroyEvent());
getEventBus().destroy(); getEventBus().destroy();
} }
} catch (final Exception e) { } catch (final Throwable e) {
Log.e(e); Log.e(e);
} }

@ -290,7 +290,7 @@ final public class EventBus implements Destroyable, BusAccess {
{ {
try { try {
if (detailedLogging) { if (detailedLogging) {
Log.f2(logMark + "Setting up channel for new event type: " + Log.str(event.getClass())); Log.f3(logMark + "Setting up channel for new event type: " + Log.str(event.getClass()));
} }
final Class<?> listener = getEventListenerClass(event); final Class<?> listener = getEventListenerClass(event);
@ -302,7 +302,7 @@ final public class EventBus implements Destroyable, BusAccess {
//channels.flush(); //channels.flush();
if (detailedLogging) { if (detailedLogging) {
Log.f2(logMark + "Created new channel: " + Log.str(event.getClass()) + " -> " + Log.str(listener)); Log.f3(logMark + "Created new channel: " + Log.str(event.getClass()) + " -> " + Log.str(listener));
} }
return true; return true;

@ -346,7 +346,7 @@ public class Log {
try { try {
hasToString = (o.getClass().getMethod("toString").getDeclaringClass() != Object.class); hasToString = (o.getClass().getMethod("toString").getDeclaringClass() != Object.class);
} catch (final Exception e) { } catch (final Throwable t) {
// oh well.. // oh well..
} }

@ -64,8 +64,8 @@ public class SimpleLog implements LogWriter {
FileHandler handler = null; FileHandler handler = null;
try { try {
handler = new FileHandler(getFile().getPath()); handler = new FileHandler(getFile().getPath());
} catch (final Exception e) { } catch (final Throwable t) {
throw new RuntimeException("Failed to init log.", e); throw new RuntimeException("Failed to init log.", t);
} }
handler.setFormatter(new LogFormatter()); handler.setFormatter(new LogFormatter());

@ -1,6 +1,8 @@
package mightypork.gamecore.resources; package mightypork.gamecore.resources;
import java.io.IOException;
import mightypork.gamecore.eventbus.events.Destroyable; import mightypork.gamecore.eventbus.events.Destroyable;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.logging.LogAlias; import mightypork.gamecore.logging.LogAlias;
@ -46,9 +48,9 @@ public abstract class BaseDeferredResource implements DeferredResource, Destroya
Log.f3("<RES> Loading: " + this); Log.f3("<RES> Loading: " + this);
loadResource(resource); loadResource(resource);
Log.f3("<RES> Loaded: " + this); Log.f3("<RES> Loaded: " + this);
} catch (final Exception e) { } catch (final Throwable t) {
loadFailed = true; loadFailed = true;
Log.e("<RES> Failed to load: " + this, e); Log.e("<RES> Failed to load: " + this, t);
} }
} }
@ -84,10 +86,10 @@ public abstract class BaseDeferredResource implements DeferredResource, Destroya
* Load the resource. Called from load() - once only. * Load the resource. Called from load() - once only.
* *
* @param resource the path / name of a resource * @param resource the path / name of a resource
* @throws Exception when some problem prevented the resource from being * @throws IOException when some problem prevented the resource from being
* loaded. * loaded.
*/ */
protected abstract void loadResource(String resource) throws Exception; protected abstract void loadResource(String resource) throws IOException;
@Override @Override

@ -8,6 +8,7 @@ import java.util.Set;
import mightypork.gamecore.core.AppAccess; import mightypork.gamecore.core.AppAccess;
import mightypork.gamecore.eventbus.clients.RootBusNode; import mightypork.gamecore.eventbus.clients.RootBusNode;
import mightypork.gamecore.eventbus.events.Updateable; import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.ResourceLoadRequest; import mightypork.gamecore.resources.ResourceLoadRequest;
import mightypork.gamecore.resources.audio.players.EffectPlayer; import mightypork.gamecore.resources.audio.players.EffectPlayer;
import mightypork.gamecore.resources.audio.players.LoopPlayer; import mightypork.gamecore.resources.audio.players.LoopPlayer;
@ -82,13 +83,18 @@ public class SoundSystem extends RootBusNode implements Updateable {
super(app); super(app);
if (!soundSystemInited) { if (!soundSystemInited) {
soundSystemInited = true;
try {
SoundStore.get().setMaxSources(MAX_SOURCES); SoundStore.get().setMaxSources(MAX_SOURCES);
SoundStore.get().init(); SoundStore.get().init();
setListener(INITIAL_LISTENER_POS); setListener(INITIAL_LISTENER_POS);
soundSystemInited = true;
getEventBus().send(new AudioReadyEvent()); getEventBus().send(new AudioReadyEvent());
} catch (final Throwable t) {
Log.e("Error initializing sound system.", t);
}
} }
} }

@ -272,8 +272,8 @@ public class CachedFont implements GLFont {
imag = null; imag = null;
} catch (final Exception e) { } catch (final Throwable t) {
Log.e("Failed to load font.", e); Log.e("Failed to load font.", t);
} }
} }
@ -325,8 +325,8 @@ public class CachedFont implements GLFont {
GLU.gluBuild2DMipmaps(GL_TEXTURE_2D, internalFormat, width, height, format, GL_UNSIGNED_BYTE, byteBuffer); GLU.gluBuild2DMipmaps(GL_TEXTURE_2D, internalFormat, width, height, format, GL_UNSIGNED_BYTE, byteBuffer);
return textureId.get(0); return textureId.get(0);
} catch (final Exception e) { } catch (final Throwable t) {
Log.e("Failed to load font.", e); Log.e("Failed to load font.", t);
} }
return -1; return -1;

@ -114,7 +114,7 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
@Override @Override
protected synchronized final void loadResource(String path) throws FontFormatException, IOException protected synchronized final void loadResource(String path) throws IOException
{ {
final Font awtFont = getAwtFont(path, (float) size, style.numval); final Font awtFont = getAwtFont(path, (float) size, style.numval);
@ -130,10 +130,9 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
* @param size font size (pt) * @param size font size (pt)
* @param style font style * @param style font style
* @return the {@link Font} * @return the {@link Font}
* @throws FontFormatException
* @throws IOException * @throws IOException
*/ */
protected Font getAwtFont(String resource, float size, int style) throws FontFormatException, IOException protected Font getAwtFont(String resource, float size, int style) throws IOException
{ {
try(InputStream in = FileUtils.getResource(resource)) { try(InputStream in = FileUtils.getResource(resource)) {
@ -143,6 +142,8 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
awtFont = awtFont.deriveFont(style); awtFont = awtFont.deriveFont(style);
return awtFont; return awtFont;
} catch (final FontFormatException e) {
throw new IOException("Could not load font, bad format.", e);
} }
} }

@ -2,7 +2,6 @@ package mightypork.gamecore.resources.fonts.impl;
import java.awt.Font; import java.awt.Font;
import java.awt.FontFormatException;
import java.io.IOException; import java.io.IOException;
import mightypork.gamecore.logging.LogAlias; import mightypork.gamecore.logging.LogAlias;
@ -34,7 +33,7 @@ public class DeferredFontNative extends DeferredFont {
@Override @Override
protected Font getAwtFont(String resource, float size, int style) throws FontFormatException, IOException protected Font getAwtFont(String resource, float size, int style) throws IOException
{ {
return new Font(resource, style, (int) size); return new Font(resource, style, (int) size);
} }

@ -189,21 +189,13 @@ public class FileUtils {
*/ */
public static List<File> listDirectory(File dir, FileFilter filter) public static List<File> listDirectory(File dir, FileFilter filter)
{ {
try {
dir.mkdir(); dir.mkdir();
} catch (final RuntimeException e) {
Log.e("Error creating folder " + dir, e);
}
final List<File> list = new ArrayList<>(); final List<File> list = new ArrayList<>();
try {
for (final File f : dir.listFiles(filter)) { for (final File f : dir.listFiles(filter)) {
list.add(f); list.add(f);
} }
} catch (final Exception e) {
Log.e("Error listing folder " + dir, e);
}
return list; return list;
} }

@ -33,9 +33,9 @@ public class InstanceLock {
fileLock.release(); fileLock.release();
randomAccessFile.close(); randomAccessFile.close();
if (!lockFile.delete()) throw new IOException(); if (!lockFile.delete()) throw new IOException();
} catch (final Exception e) { } catch (final Throwable t) {
System.err.println("Unable to remove lock file."); System.err.println("Unable to remove lock file.");
e.printStackTrace(); t.printStackTrace();
} }
} }
}); });

@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap; import java.util.TreeMap;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.objects.Convert; import mightypork.gamecore.util.objects.Convert;
@ -170,7 +171,10 @@ public class PropertyManager {
} }
} }
props.store(new FileOutputStream(file), fileComment); try(FileOutputStream fos = new FileOutputStream(file)) {
props.store(fos, fileComment);
}
} catch (final IOException ioe) { } catch (final IOException ioe) {
ioe.printStackTrace(); ioe.printStackTrace();
} }
@ -205,7 +209,8 @@ public class PropertyManager {
{ {
try { try {
return entries.get(k); return entries.get(k);
} catch (final Throwable t) { } catch (final Exception e) {
Log.w(e);
return null; return null;
} }
} }

@ -3,6 +3,7 @@ package mightypork.rogue;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.logging.Level;
import mightypork.gamecore.core.BaseApp; import mightypork.gamecore.core.BaseApp;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
@ -20,6 +21,8 @@ public class Launcher {
{ {
Log.f3("Arguments: " + Arrays.toString(args)); Log.f3("Arguments: " + Arrays.toString(args));
boolean verbose = false;
File workdir = null; File workdir = null;
try { try {
@ -27,10 +30,18 @@ public class Launcher {
String lwdDir = null; String lwdDir = null;
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
if (args[i].equals("--workdir") || args[i].equals("-w")) { final String arg = args[i];
if (arg.equals("--workdir") || arg.equals("-w")) {
localWorkdir = true; localWorkdir = true;
lwdDir = args[i + 1]; lwdDir = args[i + 1];
i++; i++;
continue;
}
if (arg.equals("--verbose") || arg.equals("-v")) {
verbose = true;
continue;
} }
} }
@ -46,8 +57,7 @@ public class Launcher {
final BaseApp app = new RogueApp(workdir, true); final BaseApp app = new RogueApp(workdir, true);
// configure the app app.opt().setLogLevel(verbose ? Level.ALL : Level.FINER);
app.opt().setBusLogging(false);
app.start(); app.start();
} }

@ -47,6 +47,7 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener, S
opt().addResources(new RogueResources()); opt().addResources(new RogueResources());
opt().addKeys(new RogueKeys()); opt().addKeys(new RogueKeys());
opt().addConfig(new RogueConfig()); opt().addConfig(new RogueConfig());
opt().setBusLogging(true);
opt().setConfigFile("config.ini", "Rogue config file"); opt().setConfigFile("config.ini", "Rogue config file");
opt().setLogOptions("logs", "runtime", 5, java.util.logging.Level.ALL); opt().setLogOptions("logs", "runtime", 5, java.util.logging.Level.ALL);

@ -111,8 +111,8 @@ public class WorldSlot extends ConstraintLayout {
getEventBus().send(new ScreenRequest("game")); getEventBus().send(new ScreenRequest("game"));
} catch (final Exception e) { } catch (final IOException t) {
Log.e("Could not create & save the world.", e); Log.e("Could not create & save the world.", t);
} }
} else { } else {

@ -107,7 +107,8 @@ public class ScreenStory extends RogueScreen implements MouseButtonHandler {
{ {
super(screen); super(screen);
TextPainter help = new TextPainter(Res.getFont("tiny"), AlignX.CENTER, RGB.WHITE.withAlpha(txProceedAlpha.mul(0.3)), "Space / click to proceed."); final TextPainter help = new TextPainter(Res.getFont("tiny"), AlignX.CENTER, RGB.WHITE.withAlpha(txProceedAlpha.mul(0.3)),
"Space / click to proceed.");
help.setRect(root.bottomEdge().growUp(root.height().perc(4))); help.setRect(root.bottomEdge().growUp(root.height().perc(4)));
help.setVPaddingPercent(5); help.setVPaddingPercent(5);
root.add(help); root.add(help);

@ -87,7 +87,7 @@ public class WorldCreator {
for (int level = 1; level <= 7; level++) { for (int level = 1; level <= 7; level++) {
final LevelBuilder lb = levelBuilders[level - 1]; final LevelBuilder lb = levelBuilders[level - 1];
final Range amount = Range.make(level/2D, level*2); final Range amount = Range.make(level / 2D, level * 2);
for (int i = 0; i < amount.randInt(rand); i++) { for (int i = 0; i < amount.randInt(rand); i++) {
lb.addItem(Calc.pick(rand, randomFood).createItem(), false); lb.addItem(Calc.pick(rand, randomFood).createItem(), false);
@ -140,7 +140,7 @@ public class WorldCreator {
lb.addRoom(Rooms.ENTRANCE, BuildOrder.FIRST, true); lb.addRoom(Rooms.ENTRANCE, BuildOrder.FIRST, true);
lb.addRoom(Rooms.BASIC, Range.make(floor/2, 2 + floor), BuildOrder.MIDDLE, false); lb.addRoom(Rooms.BASIC, Range.make(floor / 2, 2 + floor), BuildOrder.MIDDLE, false);
lb.addRoom(Rooms.DEAD_END, Range.make(1, floor), BuildOrder.MIDDLE, false); lb.addRoom(Rooms.DEAD_END, Range.make(1, floor), BuildOrder.MIDDLE, false);
lb.addRoom(Rooms.STORAGE, Range.make(1, Math.ceil(floor / 3D)), BuildOrder.MIDDLE, false); lb.addRoom(Rooms.STORAGE, Range.make(1, Math.ceil(floor / 3D)), BuildOrder.MIDDLE, false);

@ -5,9 +5,6 @@ import java.util.Random;
import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Coord;
import mightypork.rogue.world.gen.MapTheme; import mightypork.rogue.world.gen.MapTheme;
import mightypork.rogue.world.gen.RoomBuilder;
import mightypork.rogue.world.gen.RoomEntry;
import mightypork.rogue.world.gen.ScratchMap;
import mightypork.rogue.world.gen.TileProtectLevel; import mightypork.rogue.world.gen.TileProtectLevel;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
@ -17,21 +14,24 @@ public class DeadEndRoom extends AbstractRectRoom {
@Override @Override
protected Coord getInnerSize(Random rand) protected Coord getInnerSize(Random rand)
{ {
return Coord.make(1,1); return Coord.make(1, 1);
} }
@Override @Override
protected TileProtectLevel getWallProtectionLevel() protected TileProtectLevel getWallProtectionLevel()
{ {
return TileProtectLevel.STRONG; return TileProtectLevel.STRONG;
} }
@Override @Override
protected TileModel getDoorType(MapTheme theme, Random rand) protected TileModel getDoorType(MapTheme theme, Random rand)
{ {
return theme.floor(); return theme.floor();
} }
@Override @Override
protected int getDoorCount(Random rand) protected int getDoorCount(Random rand)
{ {

Loading…
Cancel
Save