--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. 16
      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. 14
      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
  19. 2
      src/mightypork/rogue/world/gen/rooms/StorageRoom.java

@ -133,6 +133,12 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
{
this.lockFile = lockFile;
}
public void setLogLevel(Level logLevel)
{
this.logLevel = logLevel;
}
}
// modules
@ -168,8 +174,6 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
{
WorkDir.init(workdir);
Log.i("Using workdir: " + WorkDir.getWorkDir());
opt.sigleInstance = singleInstance;
}
@ -222,9 +226,14 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
* Setup logging
*/
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.setLevel(opt.logLevel);
Log.setSysoutLevel(opt.logLevel);
// connect slickutil to the logger
org.newdawn.slick.util.Log.setLogSystem(new SlickLogRedirector(log));
logSystemInfo();
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()
{
Ion.registerType(Coord.ION_MARK, Coord.class);
@ -477,7 +501,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
getEventBus().send(new DestroyEvent());
getEventBus().destroy();
}
} catch (final Exception e) {
} catch (final Throwable e) {
Log.e(e);
}

@ -290,7 +290,7 @@ final public class EventBus implements Destroyable, BusAccess {
{
try {
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);
@ -302,7 +302,7 @@ final public class EventBus implements Destroyable, BusAccess {
//channels.flush();
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;

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

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

@ -1,6 +1,8 @@
package mightypork.gamecore.resources;
import java.io.IOException;
import mightypork.gamecore.eventbus.events.Destroyable;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.logging.LogAlias;
@ -46,9 +48,9 @@ public abstract class BaseDeferredResource implements DeferredResource, Destroya
Log.f3("<RES> Loading: " + this);
loadResource(resource);
Log.f3("<RES> Loaded: " + this);
} catch (final Exception e) {
} catch (final Throwable t) {
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.
*
* @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.
*/
protected abstract void loadResource(String resource) throws Exception;
protected abstract void loadResource(String resource) throws IOException;
@Override

@ -8,6 +8,7 @@ import java.util.Set;
import mightypork.gamecore.core.AppAccess;
import mightypork.gamecore.eventbus.clients.RootBusNode;
import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.ResourceLoadRequest;
import mightypork.gamecore.resources.audio.players.EffectPlayer;
import mightypork.gamecore.resources.audio.players.LoopPlayer;
@ -82,13 +83,18 @@ public class SoundSystem extends RootBusNode implements Updateable {
super(app);
if (!soundSystemInited) {
SoundStore.get().setMaxSources(MAX_SOURCES);
SoundStore.get().init();
setListener(INITIAL_LISTENER_POS);
soundSystemInited = true;
getEventBus().send(new AudioReadyEvent());
try {
SoundStore.get().setMaxSources(MAX_SOURCES);
SoundStore.get().init();
setListener(INITIAL_LISTENER_POS);
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;
} catch (final Exception e) {
Log.e("Failed to load font.", e);
} catch (final Throwable t) {
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);
return textureId.get(0);
} catch (final Exception e) {
Log.e("Failed to load font.", e);
} catch (final Throwable t) {
Log.e("Failed to load font.", t);
}
return -1;

@ -114,7 +114,7 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
@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);
@ -130,10 +130,9 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
* @param size font size (pt)
* @param style font style
* @return the {@link Font}
* @throws FontFormatException
* @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)) {
@ -143,6 +142,8 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
awtFont = awtFont.deriveFont(style);
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.FontFormatException;
import java.io.IOException;
import mightypork.gamecore.logging.LogAlias;
@ -34,7 +33,7 @@ public class DeferredFontNative extends DeferredFont {
@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);
}

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

@ -33,9 +33,9 @@ public class InstanceLock {
fileLock.release();
randomAccessFile.close();
if (!lockFile.delete()) throw new IOException();
} catch (final Exception e) {
} catch (final Throwable t) {
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.TreeMap;
import mightypork.gamecore.logging.Log;
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) {
ioe.printStackTrace();
}
@ -205,7 +209,8 @@ public class PropertyManager {
{
try {
return entries.get(k);
} catch (final Throwable t) {
} catch (final Exception e) {
Log.w(e);
return null;
}
}

@ -3,6 +3,7 @@ package mightypork.rogue;
import java.io.File;
import java.util.Arrays;
import java.util.logging.Level;
import mightypork.gamecore.core.BaseApp;
import mightypork.gamecore.logging.Log;
@ -20,6 +21,8 @@ public class Launcher {
{
Log.f3("Arguments: " + Arrays.toString(args));
boolean verbose = false;
File workdir = null;
try {
@ -27,10 +30,18 @@ public class Launcher {
String lwdDir = null;
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;
lwdDir = args[i + 1];
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);
// configure the app
app.opt().setBusLogging(false);
app.opt().setLogLevel(verbose ? Level.ALL : Level.FINER);
app.start();
}

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

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

@ -107,7 +107,8 @@ public class ScreenStory extends RogueScreen implements MouseButtonHandler {
{
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.setVPaddingPercent(5);
root.add(help);

@ -87,7 +87,7 @@ public class WorldCreator {
for (int level = 1; level <= 7; level++) {
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++) {
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.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.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.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.tile.TileModel;
@ -17,21 +14,24 @@ public class DeadEndRoom extends AbstractRectRoom {
@Override
protected Coord getInnerSize(Random rand)
{
return Coord.make(1,1);
return Coord.make(1, 1);
}
@Override
protected TileProtectLevel getWallProtectionLevel()
{
return TileProtectLevel.STRONG;
}
@Override
protected TileModel getDoorType(MapTheme theme, Random rand)
{
return theme.floor();
}
@Override
protected int getDoorCount(Random rand)
{

@ -15,7 +15,7 @@ public class StorageRoom extends SecretRoom {
@Override
protected void buildExtras(ScratchMap map, MapTheme theme, Random rand, Coord min, Coord max)
{
int maxStuff = Calc.randInt(rand, 3, 5);
int maxStuff = Calc.randInt(rand, 3, 5);
for (int i = 0; i < Calc.randInt(rand, 0, 2); i++) {
map.addItemInArea(Items.MEAT.createItem(), min, max, 50);

Loading…
Cancel
Save