some cleaning and added volatile keyword
This commit is contained in:
@@ -89,6 +89,7 @@ public class App extends BaseApp {
|
||||
log.setSysoutLevel(Level.ALL);
|
||||
log.enable(Config.LOGGING_ENABLED);
|
||||
log.enableSysout(Config.LOG_TO_STDOUT);
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
@@ -182,6 +183,8 @@ public class App extends BaseApp {
|
||||
|
||||
// custom channels
|
||||
bus.addChannel(ActionRequest.class, ActionRequest.Listener.class);
|
||||
|
||||
bus.detailedLogging = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
package mightypork.rogue;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import mightypork.gamecore.control.BaseApp;
|
||||
import mightypork.gamecore.control.GameLoop;
|
||||
import mightypork.gamecore.input.Action;
|
||||
import mightypork.gamecore.gui.Action;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.gamecore.render.Screenshot;
|
||||
import mightypork.rogue.events.ActionRequest;
|
||||
import mightypork.rogue.events.ActionRequest.RequestType;
|
||||
import mightypork.rogue.util.Utils;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
|
||||
public class MainLoop extends GameLoop implements ActionRequest.Listener {
|
||||
@@ -33,7 +42,7 @@ public class MainLoop extends GameLoop implements ActionRequest.Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/** Take a screenshot */
|
||||
/* Take a screenshot */
|
||||
private final Action taskScreenshot = new Action() {
|
||||
|
||||
@Override
|
||||
@@ -44,7 +53,7 @@ public class MainLoop extends GameLoop implements ActionRequest.Listener {
|
||||
}
|
||||
};
|
||||
|
||||
/** Shutdown the application */
|
||||
/* Shutdown the application */
|
||||
private final Action taskShutdown = new Action() {
|
||||
|
||||
@Override
|
||||
@@ -54,7 +63,7 @@ public class MainLoop extends GameLoop implements ActionRequest.Listener {
|
||||
}
|
||||
};
|
||||
|
||||
/** Toggle fullscreen */
|
||||
/* Toggle fullscreen */
|
||||
private final Action taskFullscreen = new Action() {
|
||||
|
||||
@Override
|
||||
@@ -63,4 +72,42 @@ public class MainLoop extends GameLoop implements ActionRequest.Listener {
|
||||
getDisplay().switchFullscreen();
|
||||
}
|
||||
};
|
||||
|
||||
private class TaskTakeScreenshot implements Runnable {
|
||||
|
||||
private final Screenshot scr;
|
||||
|
||||
|
||||
public TaskTakeScreenshot() {
|
||||
scr = DisplaySystem.takeScreenshot();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
|
||||
final String fname = df.format(new Date());
|
||||
|
||||
// generate unique filename
|
||||
File file;
|
||||
int index = 0;
|
||||
while (true) {
|
||||
file = new File(Paths.SCREENSHOTS, fname + (index > 0 ? "-" + index : "") + ".png");
|
||||
if (!file.exists()) break;
|
||||
index++;
|
||||
}
|
||||
|
||||
Log.f3("Saving screenshot to file: " + file);
|
||||
|
||||
// save to disk
|
||||
try {
|
||||
scr.save(file);
|
||||
} catch (final IOException e) {
|
||||
Log.e("Failed to save screenshot.", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package mightypork.rogue;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.gamecore.render.Screenshot;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
|
||||
public class TaskTakeScreenshot implements Runnable {
|
||||
|
||||
private final Screenshot scr;
|
||||
|
||||
|
||||
public TaskTakeScreenshot() {
|
||||
scr = DisplaySystem.takeScreenshot();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final String fname = getUniqueScreenshotName();
|
||||
|
||||
// generate unique filename
|
||||
File file;
|
||||
int index = 0;
|
||||
while (true) {
|
||||
file = new File(Paths.SCREENSHOTS, fname + (index > 0 ? "-" + index : "") + ".png");
|
||||
if (!file.exists()) break;
|
||||
index++;
|
||||
}
|
||||
|
||||
Log.f3("Saving screenshot to file: " + file);
|
||||
|
||||
// save to disk
|
||||
try {
|
||||
scr.save(file);
|
||||
} catch (final IOException e) {
|
||||
Log.e("Failed to save screenshot.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String getUniqueScreenshotName()
|
||||
{
|
||||
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
|
||||
return df.format(new Date());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class ScreenTestBouncy extends LayeredScreen {
|
||||
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
public String getName()
|
||||
{
|
||||
return "test.bouncy";
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ScreenTestCat extends LayeredScreen {
|
||||
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
public String getName()
|
||||
{
|
||||
return "test.cat";
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class ScreenTestFont extends Screen {
|
||||
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
public String getName()
|
||||
{
|
||||
return "test.font";
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
package mightypork.rogue.util;
|
||||
|
||||
|
||||
import mightypork.utils.logging.LogInstance;
|
||||
|
||||
import org.newdawn.slick.util.LogSystem;
|
||||
|
||||
|
||||
public class SlickLogRedirector implements LogSystem {
|
||||
|
||||
LogInstance l;
|
||||
|
||||
|
||||
public SlickLogRedirector(LogInstance log) {
|
||||
this.l = log;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void error(String msg, Throwable e)
|
||||
{
|
||||
l.e(msg, e);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void error(Throwable e)
|
||||
{
|
||||
l.e(e);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void error(String msg)
|
||||
{
|
||||
l.e(msg);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void warn(String msg)
|
||||
{
|
||||
l.w(msg);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void warn(String msg, Throwable e)
|
||||
{
|
||||
l.e(msg, e);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void info(String msg)
|
||||
{
|
||||
l.i(msg);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void debug(String msg)
|
||||
{
|
||||
l.f3(msg);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user