Huge frameworkization, config system rewrite
This commit is contained in:
@@ -13,6 +13,14 @@ import mightypork.gamecore.util.files.config.PropertyManager;
|
|||||||
*/
|
*/
|
||||||
public class Config {
|
public class Config {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config setup. Used to populate the config file.
|
||||||
|
*/
|
||||||
|
public static interface ConfigSetup {
|
||||||
|
|
||||||
|
void addOptions(PropertyManager prop);
|
||||||
|
}
|
||||||
|
|
||||||
private static PropertyManager cfg;
|
private static PropertyManager cfg;
|
||||||
|
|
||||||
|
|
||||||
@@ -22,9 +30,9 @@ public class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static PropertyManager getProp()
|
public static void registerOptions(ConfigSetup cfgl)
|
||||||
{
|
{
|
||||||
return cfg;
|
cfgl.addOptions(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package mightypork.gamecore;
|
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.util.files.config.PropertyManager;
|
|
||||||
|
|
||||||
|
|
||||||
public interface ConfigSetup {
|
|
||||||
|
|
||||||
void addOptions(PropertyManager prop);
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,8 @@ package mightypork.gamecore;
|
|||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import mightypork.gamecore.logging.Log;
|
import mightypork.gamecore.logging.Log;
|
||||||
|
|
||||||
@@ -13,7 +15,28 @@ import mightypork.gamecore.logging.Log;
|
|||||||
*/
|
*/
|
||||||
public class WorkDir {
|
public class WorkDir {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Route configurator.
|
||||||
|
*/
|
||||||
|
public static interface RouteSetup {
|
||||||
|
|
||||||
|
public void addRoutes(RouteOpts routeOpts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Route configurator access
|
||||||
|
*/
|
||||||
|
public static class RouteOpts {
|
||||||
|
|
||||||
|
public void addPath(String alias, String path)
|
||||||
|
{
|
||||||
|
WorkDir.addPath(alias, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RouteOpts routeOpts = new RouteOpts();
|
||||||
private static File workdir;
|
private static File workdir;
|
||||||
|
private static Map<String, String> namedPaths = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
public static void init(File workdir)
|
public static void init(File workdir)
|
||||||
@@ -22,6 +45,18 @@ public class WorkDir {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void addPath(String alias, String path)
|
||||||
|
{
|
||||||
|
namedPaths.put(alias, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void registerRoutes(RouteSetup rs)
|
||||||
|
{
|
||||||
|
rs.addRoutes(routeOpts);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get workdir folder, create if not exists.
|
* Get workdir folder, create if not exists.
|
||||||
*
|
*
|
||||||
@@ -30,9 +65,13 @@ public class WorkDir {
|
|||||||
*/
|
*/
|
||||||
public static File getDir(String path)
|
public static File getDir(String path)
|
||||||
{
|
{
|
||||||
|
if (namedPaths.containsKey(path)) path = namedPaths.get(path);
|
||||||
|
|
||||||
final File f = new File(workdir, path);
|
final File f = new File(workdir, path);
|
||||||
if (!f.exists() && !f.mkdirs()) {
|
if (!f.exists()) {
|
||||||
Log.w("Could not create a directory: " + f);
|
if (!f.mkdirs()) {
|
||||||
|
Log.w("Could not create a directory: " + f + " (path: " + path + ")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
@@ -47,10 +86,14 @@ public class WorkDir {
|
|||||||
*/
|
*/
|
||||||
public static File getFile(String path)
|
public static File getFile(String path)
|
||||||
{
|
{
|
||||||
|
if (namedPaths.containsKey(path)) path = namedPaths.get(path);
|
||||||
|
|
||||||
final File f = new File(workdir, path);
|
final File f = new File(workdir, path);
|
||||||
|
|
||||||
// create the parent dir
|
// create the parent dir
|
||||||
getDir(f.getParent());
|
if (!f.getParent().equals(workdir)) {
|
||||||
|
f.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
|
|
||||||
@@ -61,4 +104,5 @@ public class WorkDir {
|
|||||||
{
|
{
|
||||||
return workdir;
|
return workdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
package mightypork.gamecore.app;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link MainLoopRequest} listener
|
|
||||||
*
|
|
||||||
* @author MightyPork
|
|
||||||
*/
|
|
||||||
public interface MainLoopRequestListener {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform the requested action
|
|
||||||
*
|
|
||||||
* @param request
|
|
||||||
*/
|
|
||||||
void queueTask(Runnable request);
|
|
||||||
}
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package mightypork.gamecore.app;
|
package mightypork.gamecore.core;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.eventbus.BusAccess;
|
import mightypork.gamecore.eventbus.BusAccess;
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
package mightypork.gamecore.app;
|
package mightypork.gamecore.core;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.eventbus.EventBus;
|
import mightypork.gamecore.eventbus.EventBus;
|
||||||
@@ -12,7 +12,7 @@ import mightypork.gamecore.resources.audio.SoundSystem;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public class LightAppModule implements AppAccess {
|
public class AppAccessAdapter implements AppAccess {
|
||||||
|
|
||||||
private final AppAccess app;
|
private final AppAccess app;
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ public class LightAppModule implements AppAccess {
|
|||||||
/**
|
/**
|
||||||
* @param app app access
|
* @param app app access
|
||||||
*/
|
*/
|
||||||
public LightAppModule(AppAccess app)
|
public AppAccessAdapter(AppAccess app)
|
||||||
{
|
{
|
||||||
if (app == null) throw new NullPointerException("AppAccess instance cannot be null.");
|
if (app == null) throw new NullPointerException("AppAccess instance cannot be null.");
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package mightypork.gamecore.app;
|
package mightypork.gamecore.core;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.eventbus.clients.RootBusNode;
|
import mightypork.gamecore.eventbus.clients.RootBusNode;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package mightypork.gamecore.app;
|
package mightypork.gamecore.core;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.eventbus.clients.BusNode;
|
import mightypork.gamecore.eventbus.clients.BusNode;
|
||||||
+147
-77
@@ -1,4 +1,4 @@
|
|||||||
package mightypork.gamecore.app;
|
package mightypork.gamecore.core;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -10,15 +10,16 @@ import java.util.logging.Level;
|
|||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import mightypork.gamecore.Config;
|
import mightypork.gamecore.Config;
|
||||||
import mightypork.gamecore.ConfigSetup;
|
import mightypork.gamecore.Config.ConfigSetup;
|
||||||
import mightypork.gamecore.WorkDir;
|
import mightypork.gamecore.WorkDir;
|
||||||
|
import mightypork.gamecore.WorkDir.RouteSetup;
|
||||||
import mightypork.gamecore.eventbus.EventBus;
|
import mightypork.gamecore.eventbus.EventBus;
|
||||||
import mightypork.gamecore.eventbus.events.DestroyEvent;
|
import mightypork.gamecore.eventbus.events.DestroyEvent;
|
||||||
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
||||||
import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay;
|
import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay;
|
||||||
import mightypork.gamecore.input.InputSystem;
|
import mightypork.gamecore.input.InputSystem;
|
||||||
import mightypork.gamecore.input.KeyConfig;
|
import mightypork.gamecore.input.KeyConfig;
|
||||||
import mightypork.gamecore.input.KeySetup;
|
import mightypork.gamecore.input.KeyConfig.KeySetup;
|
||||||
import mightypork.gamecore.logging.Log;
|
import mightypork.gamecore.logging.Log;
|
||||||
import mightypork.gamecore.logging.SlickLogRedirector;
|
import mightypork.gamecore.logging.SlickLogRedirector;
|
||||||
import mightypork.gamecore.logging.writers.LogWriter;
|
import mightypork.gamecore.logging.writers.LogWriter;
|
||||||
@@ -43,6 +44,86 @@ import mightypork.gamecore.util.math.algo.Move;
|
|||||||
*/
|
*/
|
||||||
public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init options holder class
|
||||||
|
*/
|
||||||
|
public class AppInitOptions {
|
||||||
|
|
||||||
|
private String logDir = "log";
|
||||||
|
private String logFilePrefix = "runtime";
|
||||||
|
private String screenshotDir = "screenshots";
|
||||||
|
private int logArchiveCount = 0;
|
||||||
|
private boolean busLogging = false;
|
||||||
|
private String configFile = "settings.cfg";
|
||||||
|
private String configComment = "Main config file";
|
||||||
|
|
||||||
|
private final List<ResourceSetup> resourceLists = new ArrayList<>();
|
||||||
|
private final List<KeySetup> keyLists = new ArrayList<>();
|
||||||
|
private final List<ConfigSetup> configLists = new ArrayList<>();
|
||||||
|
private final List<RouteSetup> routeLists = new ArrayList<>();
|
||||||
|
|
||||||
|
private ResourceLoader resourceLoader = new AsyncResourceLoader();
|
||||||
|
private Level logLevel = Level.ALL;
|
||||||
|
|
||||||
|
|
||||||
|
public void setConfigFile(BaseApp baseApp, String filename, String comment)
|
||||||
|
{
|
||||||
|
configFile = filename;
|
||||||
|
configComment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addConfig(ConfigSetup cfg)
|
||||||
|
{
|
||||||
|
configLists.add(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addKeys(KeySetup keys)
|
||||||
|
{
|
||||||
|
keyLists.add(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addRoutes(RouteSetup keys)
|
||||||
|
{
|
||||||
|
routeLists.add(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addResources(ResourceSetup res)
|
||||||
|
{
|
||||||
|
resourceLists.add(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setBusLogging(boolean yes)
|
||||||
|
{
|
||||||
|
busLogging = yes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setLogOptions(String logDir, String filePrefix, int archivedCount, Level logLevel)
|
||||||
|
{
|
||||||
|
this.logDir = logDir;
|
||||||
|
this.logFilePrefix = filePrefix;
|
||||||
|
this.logArchiveCount = archivedCount;
|
||||||
|
this.logLevel = logLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setResourceLoader(ResourceLoader resLoader)
|
||||||
|
{
|
||||||
|
resourceLoader = resLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setScreenshotDir(String path)
|
||||||
|
{
|
||||||
|
this.screenshotDir = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// modules
|
// modules
|
||||||
private InputSystem inputSystem;
|
private InputSystem inputSystem;
|
||||||
private DisplaySystem displaySystem;
|
private DisplaySystem displaySystem;
|
||||||
@@ -50,74 +131,37 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
private MainLoop gameLoop;
|
private MainLoop gameLoop;
|
||||||
private ScreenRegistry screenRegistry;
|
private ScreenRegistry screenRegistry;
|
||||||
|
private boolean started = false;
|
||||||
|
|
||||||
private String logDirName = "log";
|
// init opt holder
|
||||||
private String logFilePrefix = "runtime";
|
private final AppInitOptions opt = new AppInitOptions();
|
||||||
private int logArchiveCount = 0;
|
|
||||||
private boolean busLogging = false;
|
|
||||||
private String configFile = "settings.cfg";
|
/**
|
||||||
private String configComment = "Main config file";
|
* Get init options
|
||||||
private final List<ResourceSetup> resourcesToLoad = new ArrayList<>();
|
*
|
||||||
private final List<KeySetup> keysToLoad = new ArrayList<>();
|
* @return opt holder
|
||||||
private final List<ConfigSetup> cfgsToLoad = new ArrayList<>();
|
*/
|
||||||
private ResourceLoader resourceLoader = new AsyncResourceLoader();
|
public AppInitOptions opt()
|
||||||
private Level logLevel = Level.ALL;
|
{
|
||||||
|
if (started) {
|
||||||
|
throw new IllegalStateException("Cannot alter init options after starting the App.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public BaseApp(File workdir, boolean singleInstance)
|
public BaseApp(File workdir, boolean singleInstance)
|
||||||
{
|
{
|
||||||
WorkDir.init(workdir);
|
WorkDir.init(workdir);
|
||||||
|
|
||||||
|
Log.i("Using workdir: " + WorkDir.getWorkDir());
|
||||||
|
|
||||||
if (singleInstance) initLock();
|
if (singleInstance) initLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setConfigFile(String filename, String comment)
|
|
||||||
{
|
|
||||||
this.configFile = filename;
|
|
||||||
this.configComment = comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setLogOptions(String logDir, String filePrefix, int archived, Level logLevel)
|
|
||||||
{
|
|
||||||
this.logDirName = logDir;
|
|
||||||
this.logFilePrefix = filePrefix;
|
|
||||||
this.logArchiveCount = archived;
|
|
||||||
this.logLevel = logLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setBusLogging(boolean yes)
|
|
||||||
{
|
|
||||||
this.busLogging = yes;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void addResources(ResourceSetup res)
|
|
||||||
{
|
|
||||||
this.resourcesToLoad.add(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void addKeys(KeySetup keys)
|
|
||||||
{
|
|
||||||
this.keysToLoad.add(keys);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void addConfig(ConfigSetup cfg)
|
|
||||||
{
|
|
||||||
this.cfgsToLoad.add(cfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setResourceLoader(ResourceLoader resLoader)
|
|
||||||
{
|
|
||||||
this.resourceLoader = resLoader;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the application
|
* Start the application
|
||||||
*/
|
*/
|
||||||
@@ -125,13 +169,12 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
{
|
{
|
||||||
Thread.setDefaultUncaughtExceptionHandler(this);
|
Thread.setDefaultUncaughtExceptionHandler(this);
|
||||||
|
|
||||||
Log.i("Using workdir: " + WorkDir.getWorkDir());
|
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
Log.i("Starting main loop...");
|
Log.i("Starting main loop...");
|
||||||
|
|
||||||
// open first screen
|
// open first screen
|
||||||
|
started = true;
|
||||||
gameLoop.start();
|
gameLoop.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,13 +184,25 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
*/
|
*/
|
||||||
protected void initialize()
|
protected void initialize()
|
||||||
{
|
{
|
||||||
Config.init(WorkDir.getFile(configFile), configComment);
|
WorkDir.addPath("screenshots", opt.screenshotDir);
|
||||||
for (final KeySetup l : keysToLoad) {
|
WorkDir.addPath("config", opt.configFile);
|
||||||
KeyConfig.addKeyLayout(l);
|
WorkDir.addPath("logs", opt.logDir);
|
||||||
|
|
||||||
|
|
||||||
|
for (final RouteSetup rs : opt.routeLists) {
|
||||||
|
WorkDir.registerRoutes(rs);
|
||||||
}
|
}
|
||||||
KeyConfig.inst().addOptions(Config.getProp());
|
|
||||||
for (final ConfigSetup cfgl : cfgsToLoad) {
|
// apply configurations
|
||||||
cfgl.addOptions(Config.getProp());
|
Config.init(WorkDir.getFile(opt.configFile), opt.configComment);
|
||||||
|
for (final KeySetup l : opt.keyLists) {
|
||||||
|
KeyConfig.registerKeys(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add keys to config
|
||||||
|
Config.registerOptions(KeyConfig.inst());
|
||||||
|
for (final ConfigSetup cfgl : opt.configLists) {
|
||||||
|
Config.registerOptions(cfgl);
|
||||||
}
|
}
|
||||||
Config.load();
|
Config.load();
|
||||||
|
|
||||||
@@ -155,8 +210,8 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
/*
|
/*
|
||||||
* Setup logging
|
* Setup logging
|
||||||
*/
|
*/
|
||||||
final LogWriter log = Log.create(logFilePrefix, new File(WorkDir.getDir(logDirName), logFilePrefix + ".log"), logArchiveCount);
|
final LogWriter log = Log.create(opt.logFilePrefix, new File(WorkDir.getDir(opt.logDir), opt.logFilePrefix + ".log"), opt.logArchiveCount);
|
||||||
log.setLevel(logLevel);
|
log.setLevel(opt.logLevel);
|
||||||
Log.setMainLogger(log);
|
Log.setMainLogger(log);
|
||||||
org.newdawn.slick.util.Log.setLogSystem(new SlickLogRedirector(log));
|
org.newdawn.slick.util.Log.setLogSystem(new SlickLogRedirector(log));
|
||||||
|
|
||||||
@@ -164,16 +219,18 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
Log.i("=== Starting initialization sequence ===");
|
Log.i("=== Starting initialization sequence ===");
|
||||||
|
|
||||||
|
|
||||||
// hook
|
// pre-init hook
|
||||||
Log.f2("Calling pre-init hook...");
|
Log.f2("Calling pre-init hook...");
|
||||||
preInit();
|
preInit();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Event bus
|
* Event bus
|
||||||
*/
|
*/
|
||||||
Log.f2("Starting Event Bus...");
|
Log.f2("Starting Event Bus...");
|
||||||
eventBus = new EventBus();
|
eventBus = new EventBus();
|
||||||
eventBus.detailedLogging = busLogging;
|
eventBus.subscribe(this);
|
||||||
|
eventBus.detailedLogging = opt.busLogging;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ionizables
|
* Ionizables
|
||||||
@@ -181,6 +238,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
Log.f3("initializing ION...");
|
Log.f3("initializing ION...");
|
||||||
registerIonizables();
|
registerIonizables();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display
|
* Display
|
||||||
*/
|
*/
|
||||||
@@ -188,6 +246,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
displaySystem = new DisplaySystem(this);
|
displaySystem = new DisplaySystem(this);
|
||||||
initDisplay(displaySystem);
|
initDisplay(displaySystem);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Audio
|
* Audio
|
||||||
*/
|
*/
|
||||||
@@ -195,6 +254,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
soundSystem = new SoundSystem(this);
|
soundSystem = new SoundSystem(this);
|
||||||
initSoundSystem(soundSystem);
|
initSoundSystem(soundSystem);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Input
|
* Input
|
||||||
*/
|
*/
|
||||||
@@ -202,6 +262,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
inputSystem = new InputSystem(this);
|
inputSystem = new InputSystem(this);
|
||||||
initInputSystem(inputSystem);
|
initInputSystem(inputSystem);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prepare main loop
|
* Prepare main loop
|
||||||
*/
|
*/
|
||||||
@@ -210,18 +271,24 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
gameLoop = createMainLoop();
|
gameLoop = createMainLoop();
|
||||||
gameLoop.setRootRenderable(screenRegistry);
|
gameLoop.setRootRenderable(screenRegistry);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load resources
|
* Load resources
|
||||||
*
|
*
|
||||||
* Resources should be registered to banks, and AsyncResourceLoader will load them.
|
* Resources should be registered to registries, and AsyncResourceLoader will load them.
|
||||||
*/
|
*/
|
||||||
Log.f1("Loading resources...");
|
Log.f1("Loading resources...");
|
||||||
resourceLoader.init(this);
|
if (opt.resourceLoader != null) {
|
||||||
|
opt.resourceLoader.init(this);
|
||||||
|
}
|
||||||
|
|
||||||
Res.init(this);
|
Res.init(this);
|
||||||
for (final ResourceSetup rl : resourcesToLoad) {
|
|
||||||
|
for (final ResourceSetup rl : opt.resourceLists) {
|
||||||
Res.load(rl);
|
Res.load(rl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Screen registry
|
* Screen registry
|
||||||
*
|
*
|
||||||
@@ -303,7 +370,10 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
*
|
*
|
||||||
* @return the game loop.
|
* @return the game loop.
|
||||||
*/
|
*/
|
||||||
protected abstract MainLoop createMainLoop();
|
protected MainLoop createMainLoop()
|
||||||
|
{
|
||||||
|
return new MainLoop(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -408,7 +478,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
getEventBus().destroy();
|
getEventBus().destroy();
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// ignore it
|
Log.e(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i("Terminating...");
|
Log.i("Terminating...");
|
||||||
+11
-3
@@ -1,4 +1,4 @@
|
|||||||
package mightypork.gamecore.app;
|
package mightypork.gamecore.core;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
@@ -7,6 +7,8 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||||||
import mightypork.gamecore.eventbus.events.UpdateEvent;
|
import mightypork.gamecore.eventbus.events.UpdateEvent;
|
||||||
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
||||||
import mightypork.gamecore.render.Renderable;
|
import mightypork.gamecore.render.Renderable;
|
||||||
|
import mightypork.gamecore.render.TaskTakeScreenshot;
|
||||||
|
import mightypork.gamecore.render.events.ScreenshotRequestListener;
|
||||||
import mightypork.gamecore.util.annot.DefaultImpl;
|
import mightypork.gamecore.util.annot.DefaultImpl;
|
||||||
import mightypork.gamecore.util.math.timing.TimerDelta;
|
import mightypork.gamecore.util.math.timing.TimerDelta;
|
||||||
|
|
||||||
@@ -16,7 +18,7 @@ import mightypork.gamecore.util.math.timing.TimerDelta;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public abstract class MainLoop extends AppModule implements MainLoopRequestListener {
|
public class MainLoop extends AppModule implements ScreenshotRequestListener {
|
||||||
|
|
||||||
private final Queue<Runnable> taskQueue = new ConcurrentLinkedQueue<>();
|
private final Queue<Runnable> taskQueue = new ConcurrentLinkedQueue<>();
|
||||||
private TimerDelta timer;
|
private TimerDelta timer;
|
||||||
@@ -102,10 +104,16 @@ public abstract class MainLoop extends AppModule implements MainLoopRequestListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void queueTask(Runnable request)
|
public synchronized void queueTask(Runnable request)
|
||||||
{
|
{
|
||||||
taskQueue.add(request);
|
taskQueue.add(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onScreenshotRequest()
|
||||||
|
{
|
||||||
|
queueTask(new TaskTakeScreenshot());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
package mightypork.gamecore.app;
|
package mightypork.gamecore.core;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.eventbus.BusEvent;
|
import mightypork.gamecore.eventbus.BusEvent;
|
||||||
@@ -11,7 +11,7 @@ import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
|
|||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
@SingleReceiverEvent
|
@SingleReceiverEvent
|
||||||
public class MainLoopRequest extends BusEvent<MainLoopRequestListener> {
|
public class MainLoopRequest extends BusEvent<MainLoop> {
|
||||||
|
|
||||||
private final Runnable task;
|
private final Runnable task;
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ public class MainLoopRequest extends BusEvent<MainLoopRequestListener> {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleBy(MainLoopRequestListener handler)
|
public void handleBy(MainLoop handler)
|
||||||
{
|
{
|
||||||
handler.queueTask(task);
|
handler.queueTask(task);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package mightypork.gamecore.core;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.gamecore.eventbus.BusEvent;
|
||||||
|
import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shutdown request. Shutdown needs to execute on GL thread for display to
|
||||||
|
* deinit properly.
|
||||||
|
*
|
||||||
|
* @author MightyPork
|
||||||
|
*/
|
||||||
|
@SingleReceiverEvent
|
||||||
|
public class ShudownRequest extends BusEvent<MainLoop> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleBy(final MainLoop handler)
|
||||||
|
{
|
||||||
|
handler.queueTask(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
handler.shutdown();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ package mightypork.gamecore.eventbus;
|
|||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.eventbus.event_flags.DelayedEvent;
|
import mightypork.gamecore.eventbus.event_flags.DelayedEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.ImmediateEvent;
|
import mightypork.gamecore.eventbus.event_flags.DirectEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
|
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
|
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
|
import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
|
||||||
@@ -14,7 +14,7 @@ import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
|
|||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* Can be annotated as {@link SingleReceiverEvent} to be delivered once only,
|
* Can be annotated as {@link SingleReceiverEvent} to be delivered once only,
|
||||||
* and {@link DelayedEvent} or {@link ImmediateEvent} to specify default sending
|
* and {@link DelayedEvent} or {@link DirectEvent} to specify default sending
|
||||||
* mode. When marked as {@link NotLoggedEvent}, it will not appear in detailed
|
* mode. When marked as {@link NotLoggedEvent}, it will not appear in detailed
|
||||||
* bus logging (useful for very frequent events, such as UpdateEvent).
|
* bus logging (useful for very frequent events, such as UpdateEvent).
|
||||||
* </p>
|
* </p>
|
||||||
@@ -111,4 +111,11 @@ public abstract class BusEvent<HANDLER> {
|
|||||||
consumed = false;
|
consumed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after all clients have received the event.
|
||||||
|
*/
|
||||||
|
public void onDispatchComplete(EventBus bus)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
import mightypork.gamecore.eventbus.clients.DelegatingClient;
|
import mightypork.gamecore.eventbus.clients.DelegatingClient;
|
||||||
import mightypork.gamecore.eventbus.event_flags.DelayedEvent;
|
import mightypork.gamecore.eventbus.event_flags.DelayedEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.ImmediateEvent;
|
import mightypork.gamecore.eventbus.event_flags.DirectEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
|
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
|
||||||
import mightypork.gamecore.eventbus.events.Destroyable;
|
import mightypork.gamecore.eventbus.events.Destroyable;
|
||||||
import mightypork.gamecore.logging.Log;
|
import mightypork.gamecore.logging.Log;
|
||||||
@@ -183,7 +183,7 @@ final public class EventBus implements Destroyable, BusAccess {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.hasAnnotation(event, ImmediateEvent.class)) {
|
if (Utils.hasAnnotation(event, DirectEvent.class)) {
|
||||||
sendDirect(event);
|
sendDirect(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -342,7 +342,10 @@ final public class EventBus implements Destroyable, BusAccess {
|
|||||||
assertLive();
|
assertLive();
|
||||||
|
|
||||||
clients.setBuffering(true);
|
clients.setBuffering(true);
|
||||||
|
|
||||||
doDispatch(clients, event);
|
doDispatch(clients, event);
|
||||||
|
event.onDispatchComplete(this);
|
||||||
|
|
||||||
clients.setBuffering(false);
|
clients.setBuffering(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -13,4 +13,4 @@ import java.lang.annotation.*;
|
|||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@Inherited
|
@Inherited
|
||||||
@Documented
|
@Documented
|
||||||
public @interface ImmediateEvent {}
|
public @interface DirectEvent {}
|
||||||
@@ -2,7 +2,7 @@ package mightypork.gamecore.eventbus.events;
|
|||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.eventbus.BusEvent;
|
import mightypork.gamecore.eventbus.BusEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.ImmediateEvent;
|
import mightypork.gamecore.eventbus.event_flags.DirectEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
|
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
@ImmediateEvent
|
@DirectEvent
|
||||||
@NonConsumableEvent
|
@NonConsumableEvent
|
||||||
public class DestroyEvent extends BusEvent<Destroyable> {
|
public class DestroyEvent extends BusEvent<Destroyable> {
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package mightypork.gamecore.eventbus.events;
|
|||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.eventbus.BusEvent;
|
import mightypork.gamecore.eventbus.BusEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.ImmediateEvent;
|
import mightypork.gamecore.eventbus.event_flags.DirectEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
|
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
|
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
|
|||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
@NotLoggedEvent
|
@NotLoggedEvent
|
||||||
@ImmediateEvent
|
@DirectEvent
|
||||||
@NonConsumableEvent
|
@NonConsumableEvent
|
||||||
public class UpdateEvent extends BusEvent<Updateable> {
|
public class UpdateEvent extends BusEvent<Updateable> {
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ package mightypork.gamecore.gui.components;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.app.AppSubModule;
|
import mightypork.gamecore.core.AppSubModule;
|
||||||
import mightypork.gamecore.eventbus.EventBus;
|
import mightypork.gamecore.eventbus.EventBus;
|
||||||
import mightypork.gamecore.eventbus.clients.ClientHub;
|
import mightypork.gamecore.eventbus.clients.ClientHub;
|
||||||
import mightypork.gamecore.input.InputSystem;
|
import mightypork.gamecore.input.InputSystem;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.gamecore.gui.components.layout;
|
package mightypork.gamecore.gui.components.layout;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.components.Component;
|
import mightypork.gamecore.gui.components.Component;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
|
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.gamecore.gui.components.layout;
|
package mightypork.gamecore.gui.components.layout;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.components.Component;
|
import mightypork.gamecore.gui.components.Component;
|
||||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
|
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.gamecore.gui.components.layout;
|
package mightypork.gamecore.gui.components.layout;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.AlignX;
|
import mightypork.gamecore.gui.AlignX;
|
||||||
import mightypork.gamecore.gui.components.Component;
|
import mightypork.gamecore.gui.components.Component;
|
||||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.gamecore.gui.components.layout;
|
package mightypork.gamecore.gui.components.layout;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.AlignY;
|
import mightypork.gamecore.gui.AlignY;
|
||||||
import mightypork.gamecore.gui.components.Component;
|
import mightypork.gamecore.gui.components.Component;
|
||||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.gamecore.gui.components.layout;
|
package mightypork.gamecore.gui.components.layout;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.components.Component;
|
import mightypork.gamecore.gui.components.Component;
|
||||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.builders.TiledRect;
|
import mightypork.gamecore.util.math.constraints.rect.builders.TiledRect;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.gamecore.gui.components.layout;
|
package mightypork.gamecore.gui.components.layout;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.components.Component;
|
import mightypork.gamecore.gui.components.Component;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
|
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.gamecore.gui.components.layout.linear;
|
package mightypork.gamecore.gui.components.layout.linear;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.AlignX;
|
import mightypork.gamecore.gui.AlignX;
|
||||||
import mightypork.gamecore.gui.components.DynamicWidthComponent;
|
import mightypork.gamecore.gui.components.DynamicWidthComponent;
|
||||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package mightypork.gamecore.gui.events;
|
|||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.eventbus.BusEvent;
|
import mightypork.gamecore.eventbus.BusEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.ImmediateEvent;
|
import mightypork.gamecore.eventbus.event_flags.DirectEvent;
|
||||||
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
|
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
|
||||||
|
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
@ImmediateEvent
|
@DirectEvent
|
||||||
@NonConsumableEvent
|
@NonConsumableEvent
|
||||||
public class LayoutChangeEvent extends BusEvent<LayoutChangeListener> {
|
public class LayoutChangeEvent extends BusEvent<LayoutChangeListener> {
|
||||||
|
|
||||||
|
|||||||
@@ -16,39 +16,15 @@ import mightypork.gamecore.util.math.constraints.vect.Vect;
|
|||||||
@NotLoggedEvent
|
@NotLoggedEvent
|
||||||
public class ViewportChangeEvent extends BusEvent<ViewportChangeListener> {
|
public class ViewportChangeEvent extends BusEvent<ViewportChangeListener> {
|
||||||
|
|
||||||
private final boolean fullscreen;
|
|
||||||
private final Vect screenSize;
|
private final Vect screenSize;
|
||||||
private final boolean fsChanged;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param fsChanged fullscreen change triggered the event
|
|
||||||
* @param fullscreen is now fullscreen
|
|
||||||
* @param size new screen size
|
* @param size new screen size
|
||||||
*/
|
*/
|
||||||
public ViewportChangeEvent(boolean fsChanged, boolean fullscreen, Vect size)
|
public ViewportChangeEvent(Vect size)
|
||||||
{
|
{
|
||||||
this.fullscreen = fullscreen;
|
|
||||||
this.screenSize = size;
|
this.screenSize = size;
|
||||||
this.fsChanged = fsChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if screen is now fullscreen
|
|
||||||
*/
|
|
||||||
public boolean isFullscreen()
|
|
||||||
{
|
|
||||||
return fullscreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if event was triggered by fullscreen toggle
|
|
||||||
*/
|
|
||||||
public boolean fullscreenChanged()
|
|
||||||
{
|
|
||||||
return fsChanged;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.util.Collection;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.eventbus.clients.DelegatingClient;
|
import mightypork.gamecore.eventbus.clients.DelegatingClient;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ package mightypork.gamecore.gui.screens;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.app.AppSubModule;
|
import mightypork.gamecore.core.AppSubModule;
|
||||||
import mightypork.gamecore.eventbus.events.Updateable;
|
import mightypork.gamecore.eventbus.events.Updateable;
|
||||||
import mightypork.gamecore.gui.Enableable;
|
import mightypork.gamecore.gui.Enableable;
|
||||||
import mightypork.gamecore.gui.Hideable;
|
import mightypork.gamecore.gui.Hideable;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package mightypork.gamecore.gui.screens;
|
package mightypork.gamecore.gui.screens;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.app.AppSubModule;
|
import mightypork.gamecore.core.AppSubModule;
|
||||||
import mightypork.gamecore.gui.events.LayoutChangeEvent;
|
import mightypork.gamecore.gui.events.LayoutChangeEvent;
|
||||||
import mightypork.gamecore.gui.events.LayoutChangeListener;
|
import mightypork.gamecore.gui.events.LayoutChangeListener;
|
||||||
import mightypork.gamecore.input.KeyBinder;
|
import mightypork.gamecore.input.KeyBinder;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.app.AppModule;
|
import mightypork.gamecore.core.AppModule;
|
||||||
import mightypork.gamecore.gui.events.LayoutChangeEvent;
|
import mightypork.gamecore.gui.events.LayoutChangeEvent;
|
||||||
import mightypork.gamecore.gui.events.ScreenRequestListener;
|
import mightypork.gamecore.gui.events.ScreenRequestListener;
|
||||||
import mightypork.gamecore.gui.events.ViewportChangeEvent;
|
import mightypork.gamecore.gui.events.ViewportChangeEvent;
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package mightypork.gamecore.gui.screens.impl;
|
package mightypork.gamecore.gui.screens.impl;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
|
import mightypork.gamecore.core.ShudownRequest;
|
||||||
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
||||||
import mightypork.gamecore.gui.events.ScreenRequest;
|
import mightypork.gamecore.gui.events.ScreenRequest;
|
||||||
import mightypork.gamecore.gui.screens.Overlay;
|
import mightypork.gamecore.gui.screens.Overlay;
|
||||||
@@ -9,8 +10,6 @@ import mightypork.gamecore.util.math.Easing;
|
|||||||
import mightypork.gamecore.util.math.color.pal.RGB;
|
import mightypork.gamecore.util.math.color.pal.RGB;
|
||||||
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
|
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
|
||||||
import mightypork.gamecore.util.math.timing.TimedTask;
|
import mightypork.gamecore.util.math.timing.TimedTask;
|
||||||
import mightypork.rogue.events.ActionRequest;
|
|
||||||
import mightypork.rogue.events.ActionRequest.RequestType;
|
|
||||||
|
|
||||||
|
|
||||||
public class CrossfadeOverlay extends Overlay {
|
public class CrossfadeOverlay extends Overlay {
|
||||||
@@ -27,7 +26,7 @@ public class CrossfadeOverlay extends Overlay {
|
|||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
if (requestedScreenName == null) {
|
if (requestedScreenName == null) {
|
||||||
getEventBus().send(new ActionRequest(RequestType.SHUTDOWN));
|
getEventBus().send(new ShudownRequest());
|
||||||
} else {
|
} else {
|
||||||
getEventBus().send(new ScreenRequest(requestedScreenName));
|
getEventBus().send(new ScreenRequest(requestedScreenName));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package mightypork.gamecore.input;
|
package mightypork.gamecore.input;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
|
import mightypork.gamecore.core.ShudownRequest;
|
||||||
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.input.KeyStroke.Edge;
|
import mightypork.gamecore.input.KeyStroke.Edge;
|
||||||
@@ -11,8 +12,6 @@ import mightypork.gamecore.input.events.MouseButtonEvent;
|
|||||||
import mightypork.gamecore.input.events.MouseMotionEvent;
|
import mightypork.gamecore.input.events.MouseMotionEvent;
|
||||||
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
||||||
import mightypork.gamecore.util.math.constraints.vect.mutable.VectVar;
|
import mightypork.gamecore.util.math.constraints.vect.mutable.VectVar;
|
||||||
import mightypork.rogue.events.ActionRequest;
|
|
||||||
import mightypork.rogue.events.ActionRequest.RequestType;
|
|
||||||
|
|
||||||
import org.lwjgl.LWJGLException;
|
import org.lwjgl.LWJGLException;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
@@ -140,7 +139,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Display.isCloseRequested()) {
|
if (Display.isCloseRequested()) {
|
||||||
getEventBus().send(new ActionRequest(RequestType.SHUTDOWN));
|
getEventBus().send(new ShudownRequest());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,32 @@ package mightypork.gamecore.input;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import mightypork.gamecore.ConfigSetup;
|
import mightypork.gamecore.Config.ConfigSetup;
|
||||||
import mightypork.gamecore.util.files.config.Property;
|
import mightypork.gamecore.util.files.config.Property;
|
||||||
import mightypork.gamecore.util.files.config.PropertyManager;
|
import mightypork.gamecore.util.files.config.PropertyManager;
|
||||||
|
|
||||||
|
|
||||||
public class KeyConfig implements ConfigSetup {
|
public class KeyConfig implements ConfigSetup {
|
||||||
|
|
||||||
private static KeyConfig inst = new KeyConfig();
|
/**
|
||||||
|
* Key configurator
|
||||||
|
*/
|
||||||
|
public static interface KeySetup {
|
||||||
|
|
||||||
|
public void addKeys(KeyOpts keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key configurator access
|
||||||
|
*/
|
||||||
|
public static class KeyOpts {
|
||||||
|
|
||||||
|
public void add(String cfgKey, String dataString)
|
||||||
|
{
|
||||||
|
strokes.put(prefixKey(cfgKey), new KeyProperty(prefixKey(cfgKey), KeyStroke.createFromDataString(dataString), null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key property.<br>
|
* Key property.<br>
|
||||||
@@ -62,16 +80,28 @@ public class KeyConfig implements ConfigSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static KeyConfig inst = new KeyConfig();
|
||||||
|
public static KeyOpts keyOpts = new KeyOpts();
|
||||||
|
|
||||||
private static Map<String, KeyProperty> strokes = new HashMap<>();
|
private static Map<String, KeyProperty> strokes = new HashMap<>();
|
||||||
private static PropertyManager prop;
|
private static PropertyManager prop;
|
||||||
|
|
||||||
|
|
||||||
public static void addKeyLayout(KeySetup layout)
|
public static void registerKeys(KeySetup layout)
|
||||||
{
|
{
|
||||||
layout.addKeys(inst);
|
layout.addKeys(keyOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String prefixKey(String cfgKey)
|
||||||
|
{
|
||||||
|
return "key." + cfgKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add key options to a config manager
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addOptions(PropertyManager prop)
|
public void addOptions(PropertyManager prop)
|
||||||
{
|
{
|
||||||
@@ -83,15 +113,9 @@ public class KeyConfig implements ConfigSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void add(String cfgKey, String dataString)
|
|
||||||
{
|
|
||||||
strokes.put(cfgKey, new KeyProperty(cfgKey, KeyStroke.createFromDataString(dataString), null));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static KeyStroke get(String cfgKey)
|
public static KeyStroke get(String cfgKey)
|
||||||
{
|
{
|
||||||
final KeyProperty kp = strokes.get(cfgKey);
|
final KeyProperty kp = strokes.get(prefixKey(cfgKey));
|
||||||
if (kp == null) throw new IllegalArgumentException("No such stroke: " + cfgKey);
|
if (kp == null) throw new IllegalArgumentException("No such stroke: " + cfgKey);
|
||||||
return kp.getValue();
|
return kp.getValue();
|
||||||
}
|
}
|
||||||
@@ -99,7 +123,7 @@ public class KeyConfig implements ConfigSetup {
|
|||||||
|
|
||||||
public static void set(String cfgKey, int key, int mod)
|
public static void set(String cfgKey, int key, int mod)
|
||||||
{
|
{
|
||||||
final KeyProperty kp = strokes.get(cfgKey);
|
final KeyProperty kp = strokes.get(prefixKey(cfgKey));
|
||||||
if (kp == null) throw new IllegalArgumentException("No such stroke: " + cfgKey);
|
if (kp == null) throw new IllegalArgumentException("No such stroke: " + cfgKey);
|
||||||
|
|
||||||
kp.getValue().setTo(key, mod);
|
kp.getValue().setTo(key, mod);
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
package mightypork.gamecore.input;
|
|
||||||
|
|
||||||
|
|
||||||
public interface KeySetup {
|
|
||||||
|
|
||||||
public void addKeys(KeyConfig keys);
|
|
||||||
}
|
|
||||||
@@ -292,15 +292,18 @@ public class Log {
|
|||||||
|
|
||||||
public static String formatMessage(Level level, String message, Throwable throwable, long start_ms)
|
public static String formatMessage(Level level, String message, Throwable throwable, long start_ms)
|
||||||
{
|
{
|
||||||
|
if (message == null) message = "";
|
||||||
|
|
||||||
final String nl = System.getProperty("line.separator");
|
final String nl = System.getProperty("line.separator");
|
||||||
|
|
||||||
if (message.equals("\n")) {
|
if (message.length() > 0) {
|
||||||
return nl;
|
if (message.equals("\n")) {
|
||||||
}
|
return nl;
|
||||||
|
}
|
||||||
|
|
||||||
if (message.charAt(0) == '\n') {
|
if (message.charAt(0) == '\n') {
|
||||||
message = nl + message.substring(1);
|
message = nl + message.substring(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final long time_ms = (System.currentTimeMillis() - start_ms);
|
final long time_ms = (System.currentTimeMillis() - start_ms);
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import static org.lwjgl.opengl.GL11.*;
|
|||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.app.AppModule;
|
import mightypork.gamecore.core.AppModule;
|
||||||
import mightypork.gamecore.gui.events.ViewportChangeEvent;
|
import mightypork.gamecore.gui.events.ViewportChangeEvent;
|
||||||
import mightypork.gamecore.logging.Log;
|
import mightypork.gamecore.logging.Log;
|
||||||
|
import mightypork.gamecore.render.events.DisplayReadyEvent;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
|
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
|
||||||
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
||||||
@@ -30,6 +31,7 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
private DisplayMode windowDisplayMode;
|
private DisplayMode windowDisplayMode;
|
||||||
private int targetFps;
|
private int targetFps;
|
||||||
private FpsMeter fpsMeter;
|
private FpsMeter fpsMeter;
|
||||||
|
private boolean fullscreenSwitchRequested;
|
||||||
|
|
||||||
/** Current screen size */
|
/** Current screen size */
|
||||||
private static final Vect screenSize = new Vect() {
|
private static final Vect screenSize = new Vect() {
|
||||||
@@ -116,6 +118,12 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
* Toggle FS if possible
|
* Toggle FS if possible
|
||||||
*/
|
*/
|
||||||
public void switchFullscreen()
|
public void switchFullscreen()
|
||||||
|
{
|
||||||
|
fullscreenSwitchRequested = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void doSwitchFullscreen()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -133,7 +141,7 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
Display.update();
|
Display.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
getEventBus().send(new ViewportChangeEvent(true, Display.isFullscreen(), getSize()));
|
getEventBus().send(new ViewportChangeEvent(getSize()));
|
||||||
|
|
||||||
} catch (final Throwable t) {
|
} catch (final Throwable t) {
|
||||||
Log.e("Failed to toggle fullscreen mode.", t);
|
Log.e("Failed to toggle fullscreen mode.", t);
|
||||||
@@ -153,7 +161,7 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
*
|
*
|
||||||
* @return screenshot object
|
* @return screenshot object
|
||||||
*/
|
*/
|
||||||
public Screenshot takeScreenshot()
|
public static Screenshot prepareScreenshot()
|
||||||
{
|
{
|
||||||
glReadBuffer(GL_FRONT);
|
glReadBuffer(GL_FRONT);
|
||||||
final int width = Display.getWidth();
|
final int width = Display.getWidth();
|
||||||
@@ -235,9 +243,11 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
{
|
{
|
||||||
// handle resize
|
// handle resize
|
||||||
if (Display.wasResized()) {
|
if (Display.wasResized()) {
|
||||||
getEventBus().send(new ViewportChangeEvent(false, Display.isFullscreen(), getSize()));
|
getEventBus().send(new ViewportChangeEvent(getSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fullscreenSwitchRequested) doSwitchFullscreen();
|
||||||
|
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
fpsMeter.frame();
|
fpsMeter.frame();
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ public class Render {
|
|||||||
{
|
{
|
||||||
pushed++;
|
pushed++;
|
||||||
|
|
||||||
if (pushed >= 20) {
|
if (pushed >= 100) {
|
||||||
Log.w("Suspicious number of state pushes: " + pushed);
|
Log.w("Suspicious number of state pushes: " + pushed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,14 +528,14 @@ public class Render {
|
|||||||
public static void enterBatchTexturedQuadMode(GLTexture texture)
|
public static void enterBatchTexturedQuadMode(GLTexture texture)
|
||||||
{
|
{
|
||||||
texture.bind();
|
texture.bind();
|
||||||
GL11.glBegin(GL11.GL_QUADS);
|
glBegin(GL11.GL_QUADS);
|
||||||
batchTexturedQuadMode = true;
|
batchTexturedQuadMode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void leaveBatchTexturedQuadMode()
|
public static void leaveBatchTexturedQuadMode()
|
||||||
{
|
{
|
||||||
GL11.glEnd();
|
glEnd();
|
||||||
batchTexturedQuadMode = false;
|
batchTexturedQuadMode = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package mightypork.gamecore.render;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import mightypork.gamecore.WorkDir;
|
||||||
|
import mightypork.gamecore.logging.Log;
|
||||||
|
|
||||||
|
import org.newdawn.slick.opengl.GLUtils;
|
||||||
|
|
||||||
|
|
||||||
|
public class TaskTakeScreenshot implements Runnable {
|
||||||
|
|
||||||
|
private final Screenshot scr;
|
||||||
|
|
||||||
|
|
||||||
|
public TaskTakeScreenshot()
|
||||||
|
{
|
||||||
|
GLUtils.checkGLContext();
|
||||||
|
scr = DisplaySystem.prepareScreenshot();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@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(WorkDir.getDir("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
-1
@@ -1,4 +1,4 @@
|
|||||||
package mightypork.gamecore.render;
|
package mightypork.gamecore.render.events;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.eventbus.BusEvent;
|
import mightypork.gamecore.eventbus.BusEvent;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package mightypork.gamecore.render;
|
package mightypork.gamecore.render.events;
|
||||||
|
|
||||||
|
|
||||||
public interface DisplayReadyListener {
|
public interface DisplayReadyListener {
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package mightypork.gamecore.render.events;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.gamecore.eventbus.BusEvent;
|
||||||
|
import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
|
||||||
|
import mightypork.gamecore.render.DisplaySystem;
|
||||||
|
|
||||||
|
|
||||||
|
@SingleReceiverEvent
|
||||||
|
public class FullscreenToggleRequest extends BusEvent<DisplaySystem> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleBy(DisplaySystem handler)
|
||||||
|
{
|
||||||
|
handler.switchFullscreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package mightypork.gamecore.render.events;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.gamecore.eventbus.BusEvent;
|
||||||
|
|
||||||
|
|
||||||
|
public class ScreenshotRequest extends BusEvent<ScreenshotRequestListener> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleBy(ScreenshotRequestListener handler)
|
||||||
|
{
|
||||||
|
handler.onScreenshotRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package mightypork.gamecore.render.events;
|
||||||
|
|
||||||
|
|
||||||
|
public interface ScreenshotRequestListener {
|
||||||
|
|
||||||
|
public void onScreenshotRequest();
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
import mightypork.gamecore.app.MainLoopRequest;
|
import mightypork.gamecore.core.MainLoopRequest;
|
||||||
import mightypork.gamecore.eventbus.BusAccess;
|
import mightypork.gamecore.eventbus.BusAccess;
|
||||||
import mightypork.gamecore.eventbus.events.Destroyable;
|
import mightypork.gamecore.eventbus.events.Destroyable;
|
||||||
import mightypork.gamecore.logging.Log;
|
import mightypork.gamecore.logging.Log;
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package mightypork.gamecore.resources;
|
package mightypork.gamecore.resources;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.resources.audio.SoundBank;
|
import mightypork.gamecore.resources.audio.SoundRegistry;
|
||||||
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;
|
||||||
import mightypork.gamecore.resources.fonts.FontBank;
|
import mightypork.gamecore.resources.fonts.FontRegistry;
|
||||||
import mightypork.gamecore.resources.fonts.GLFont;
|
import mightypork.gamecore.resources.fonts.GLFont;
|
||||||
import mightypork.gamecore.resources.textures.GLTexture;
|
import mightypork.gamecore.resources.textures.GLTexture;
|
||||||
import mightypork.gamecore.resources.textures.TextureBank;
|
import mightypork.gamecore.resources.textures.TextureRegistry;
|
||||||
import mightypork.gamecore.resources.textures.TxQuad;
|
import mightypork.gamecore.resources.textures.TxQuad;
|
||||||
import mightypork.gamecore.resources.textures.TxSheet;
|
import mightypork.gamecore.resources.textures.TxSheet;
|
||||||
|
|
||||||
@@ -20,9 +20,9 @@ import mightypork.gamecore.resources.textures.TxSheet;
|
|||||||
*/
|
*/
|
||||||
public final class Res {
|
public final class Res {
|
||||||
|
|
||||||
private static TextureBank textures;
|
private static TextureRegistry textures;
|
||||||
private static SoundBank sounds;
|
private static SoundRegistry sounds;
|
||||||
private static FontBank fonts;
|
private static FontRegistry fonts;
|
||||||
|
|
||||||
private static boolean initialized = false;
|
private static boolean initialized = false;
|
||||||
|
|
||||||
@@ -37,9 +37,9 @@ public final class Res {
|
|||||||
if (initialized) return;
|
if (initialized) return;
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
textures = new TextureBank(app);
|
textures = new TextureRegistry(app);
|
||||||
sounds = new SoundBank(app);
|
sounds = new SoundRegistry(app);
|
||||||
fonts = new FontBank(app);
|
fonts = new FontRegistry(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public interface ResourceLoader {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the loader (async loader may start a stread)
|
* Initialize the loader (Join the bus, start a stread etc)
|
||||||
*
|
*
|
||||||
* @param app app the loader works for. The event bus must already be
|
* @param app app the loader works for. The event bus must already be
|
||||||
* initialized.
|
* initialized.
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package mightypork.gamecore.resources;
|
package mightypork.gamecore.resources;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.resources.audio.SoundBank;
|
import mightypork.gamecore.resources.audio.SoundRegistry;
|
||||||
import mightypork.gamecore.resources.fonts.FontBank;
|
import mightypork.gamecore.resources.fonts.FontRegistry;
|
||||||
import mightypork.gamecore.resources.textures.TextureBank;
|
import mightypork.gamecore.resources.textures.TextureRegistry;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,7 +18,7 @@ public interface ResourceSetup {
|
|||||||
*
|
*
|
||||||
* @param fonts font registry
|
* @param fonts font registry
|
||||||
*/
|
*/
|
||||||
void addFonts(FontBank fonts);
|
void addFonts(FontRegistry fonts);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,7 +26,7 @@ public interface ResourceSetup {
|
|||||||
*
|
*
|
||||||
* @param sounds sound registry
|
* @param sounds sound registry
|
||||||
*/
|
*/
|
||||||
void addSounds(SoundBank sounds);
|
void addSounds(SoundRegistry sounds);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,5 +34,5 @@ public interface ResourceSetup {
|
|||||||
*
|
*
|
||||||
* @param textures texture registry
|
* @param textures texture registry
|
||||||
*/
|
*/
|
||||||
void addTextures(TextureBank textures);
|
void addTextures(TextureRegistry textures);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -4,8 +4,8 @@ package mightypork.gamecore.resources.audio;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.app.LightAppModule;
|
import mightypork.gamecore.core.AppAccessAdapter;
|
||||||
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;
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ import mightypork.gamecore.resources.audio.players.LoopPlayer;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public class SoundBank extends LightAppModule {
|
public class SoundRegistry extends AppAccessAdapter {
|
||||||
|
|
||||||
private final Map<String, EffectPlayer> effects = new HashMap<>();
|
private final Map<String, EffectPlayer> effects = new HashMap<>();
|
||||||
private final Map<String, LoopPlayer> loops = new HashMap<>();
|
private final Map<String, LoopPlayer> loops = new HashMap<>();
|
||||||
@@ -24,7 +24,7 @@ public class SoundBank extends LightAppModule {
|
|||||||
/**
|
/**
|
||||||
* @param app app access
|
* @param app app access
|
||||||
*/
|
*/
|
||||||
public SoundBank(AppAccess app)
|
public SoundRegistry(AppAccess app)
|
||||||
{
|
{
|
||||||
super(app);
|
super(app);
|
||||||
if (getSoundSystem() == null) throw new NullPointerException("SoundSystem cannot be null.");
|
if (getSoundSystem() == null) throw new NullPointerException("SoundSystem cannot be null.");
|
||||||
@@ -5,7 +5,7 @@ import java.nio.FloatBuffer;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import mightypork.gamecore.app.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.resources.ResourceLoadRequest;
|
import mightypork.gamecore.resources.ResourceLoadRequest;
|
||||||
|
|||||||
+4
-4
@@ -3,8 +3,8 @@ package mightypork.gamecore.resources.fonts;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.app.LightAppModule;
|
import mightypork.gamecore.core.AppAccessAdapter;
|
||||||
import mightypork.gamecore.resources.ResourceLoadRequest;
|
import mightypork.gamecore.resources.ResourceLoadRequest;
|
||||||
import mightypork.gamecore.resources.fonts.impl.DeferredFont;
|
import mightypork.gamecore.resources.fonts.impl.DeferredFont;
|
||||||
|
|
||||||
@@ -16,12 +16,12 @@ import org.newdawn.slick.opengl.Texture;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public class FontBank extends LightAppModule {
|
public class FontRegistry extends AppAccessAdapter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param app app access
|
* @param app app access
|
||||||
*/
|
*/
|
||||||
public FontBank(AppAccess app)
|
public FontRegistry(AppAccess app)
|
||||||
{
|
{
|
||||||
super(app);
|
super(app);
|
||||||
}
|
}
|
||||||
+4
-4
@@ -4,8 +4,8 @@ package mightypork.gamecore.resources.textures;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.app.LightAppModule;
|
import mightypork.gamecore.core.AppAccessAdapter;
|
||||||
import mightypork.gamecore.resources.ResourceLoadRequest;
|
import mightypork.gamecore.resources.ResourceLoadRequest;
|
||||||
import mightypork.gamecore.util.error.KeyAlreadyExistsException;
|
import mightypork.gamecore.util.error.KeyAlreadyExistsException;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||||||
@@ -17,7 +17,7 @@ import mightypork.gamecore.util.math.constraints.rect.Rect;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public class TextureBank extends LightAppModule {
|
public class TextureRegistry extends AppAccessAdapter {
|
||||||
|
|
||||||
private final Map<String, GLTexture> textures = new HashMap<>();
|
private final Map<String, GLTexture> textures = new HashMap<>();
|
||||||
private final Map<String, TxSheet> sheets = new HashMap<>();
|
private final Map<String, TxSheet> sheets = new HashMap<>();
|
||||||
@@ -26,7 +26,7 @@ public class TextureBank extends LightAppModule {
|
|||||||
/**
|
/**
|
||||||
* @param app app access
|
* @param app app access
|
||||||
*/
|
*/
|
||||||
public TextureBank(AppAccess app)
|
public TextureRegistry(AppAccess app)
|
||||||
{
|
{
|
||||||
super(app);
|
super(app);
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ package mightypork.rogue;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import mightypork.gamecore.app.BaseApp;
|
import mightypork.gamecore.core.BaseApp;
|
||||||
import mightypork.gamecore.logging.Log;
|
import mightypork.gamecore.logging.Log;
|
||||||
import mightypork.gamecore.util.files.OsUtils;
|
import mightypork.gamecore.util.files.OsUtils;
|
||||||
|
|
||||||
@@ -46,13 +46,8 @@ public class Launcher {
|
|||||||
|
|
||||||
final BaseApp app = new RogueApp(workdir, true);
|
final BaseApp app = new RogueApp(workdir, true);
|
||||||
|
|
||||||
app.addResources(new RogueResources());
|
// configure the app
|
||||||
app.addKeys(new RogueKeys());
|
app.opt().setBusLogging(true);
|
||||||
app.addConfig(new RogueConfig());
|
|
||||||
|
|
||||||
app.setBusLogging(false);
|
|
||||||
app.setConfigFile("config.ini", "Rogue config file");
|
|
||||||
app.setLogOptions("/", "runtime", 5, java.util.logging.Level.ALL);
|
|
||||||
|
|
||||||
app.start();
|
app.start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,20 +4,19 @@ package mightypork.rogue;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import mightypork.gamecore.Config;
|
import mightypork.gamecore.Config;
|
||||||
import mightypork.gamecore.app.BaseApp;
|
import mightypork.gamecore.core.BaseApp;
|
||||||
import mightypork.gamecore.app.MainLoop;
|
import mightypork.gamecore.core.MainLoopRequest;
|
||||||
import mightypork.gamecore.app.MainLoopRequest;
|
|
||||||
import mightypork.gamecore.eventbus.BusEvent;
|
import mightypork.gamecore.eventbus.BusEvent;
|
||||||
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
||||||
import mightypork.gamecore.input.InputSystem;
|
import mightypork.gamecore.input.InputSystem;
|
||||||
import mightypork.gamecore.input.KeyConfig;
|
import mightypork.gamecore.input.KeyConfig;
|
||||||
import mightypork.gamecore.input.KeyStroke.Edge;
|
import mightypork.gamecore.input.KeyStroke.Edge;
|
||||||
import mightypork.gamecore.render.DisplaySystem;
|
import mightypork.gamecore.render.DisplaySystem;
|
||||||
|
import mightypork.gamecore.render.events.FullscreenToggleRequest;
|
||||||
|
import mightypork.gamecore.render.events.ScreenshotRequest;
|
||||||
import mightypork.gamecore.util.ion.Ion;
|
import mightypork.gamecore.util.ion.Ion;
|
||||||
import mightypork.rogue.RogueStateManager.RogueState;
|
import mightypork.rogue.RogueStateManager.RogueState;
|
||||||
import mightypork.rogue.events.ActionRequest;
|
import mightypork.rogue.events.RogueStateRequest;
|
||||||
import mightypork.rogue.events.ActionRequest.RequestType;
|
|
||||||
import mightypork.rogue.events.GameStateRequest;
|
|
||||||
import mightypork.rogue.screens.FpsOverlay;
|
import mightypork.rogue.screens.FpsOverlay;
|
||||||
import mightypork.rogue.screens.LoadingOverlay;
|
import mightypork.rogue.screens.LoadingOverlay;
|
||||||
import mightypork.rogue.screens.game.ScreenGame;
|
import mightypork.rogue.screens.game.ScreenGame;
|
||||||
@@ -39,6 +38,14 @@ public final class RogueApp extends BaseApp {
|
|||||||
public RogueApp(File workdir, boolean singleInstance)
|
public RogueApp(File workdir, boolean singleInstance)
|
||||||
{
|
{
|
||||||
super(workdir, singleInstance);
|
super(workdir, singleInstance);
|
||||||
|
|
||||||
|
opt().addRoutes(new RogueRoutes());
|
||||||
|
opt().addResources(new RogueResources());
|
||||||
|
opt().addKeys(new RogueKeys());
|
||||||
|
opt().addConfig(new RogueConfig());
|
||||||
|
|
||||||
|
opt().setConfigFile(this, "config.ini", "Rogue config file");
|
||||||
|
opt().setLogOptions("/", "runtime", 5, java.util.logging.Level.ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -84,11 +91,11 @@ public final class RogueApp extends BaseApp {
|
|||||||
protected void initInputSystem(InputSystem input)
|
protected void initInputSystem(InputSystem input)
|
||||||
{
|
{
|
||||||
// this will work only with reusable events (such as requests)
|
// this will work only with reusable events (such as requests)
|
||||||
bindEventToKey(new ActionRequest(RequestType.FULLSCREEN), "key.global.fullscreen");
|
bindEventToKey(new FullscreenToggleRequest(), "global.fullscreen");
|
||||||
bindEventToKey(new ActionRequest(RequestType.SCREENSHOT), "key.global.screenshot");
|
bindEventToKey(new ScreenshotRequest(), "global.screenshot");
|
||||||
|
|
||||||
bindEventToKey(new GameStateRequest(RogueState.EXIT), "key.global.quit");
|
bindEventToKey(new RogueStateRequest(RogueState.EXIT), "global.quit");
|
||||||
bindEventToKey(new GameStateRequest(RogueState.MAIN_MENU), "key.global.menu");
|
bindEventToKey(new RogueStateRequest(RogueState.MAIN_MENU), "global.menu");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -105,13 +112,6 @@ public final class RogueApp extends BaseApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected MainLoop createMainLoop()
|
|
||||||
{
|
|
||||||
return new RogueMainLoop(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void postInit()
|
protected void postInit()
|
||||||
{
|
{
|
||||||
@@ -120,7 +120,7 @@ public final class RogueApp extends BaseApp {
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
getEventBus().send(new GameStateRequest(RogueState.MAIN_MENU));
|
getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU));
|
||||||
//getEventBus().send(new CrossfadeRequest("test.layout", true));
|
//getEventBus().send(new CrossfadeRequest("test.layout", true));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.rogue;
|
package mightypork.rogue;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.ConfigSetup;
|
import mightypork.gamecore.Config.ConfigSetup;
|
||||||
import mightypork.gamecore.util.files.config.PropertyManager;
|
import mightypork.gamecore.util.files.config.PropertyManager;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
package mightypork.rogue;
|
package mightypork.rogue;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.input.KeyConfig;
|
import mightypork.gamecore.input.KeyConfig.KeyOpts;
|
||||||
import mightypork.gamecore.input.KeySetup;
|
import mightypork.gamecore.input.KeyConfig.KeySetup;
|
||||||
|
|
||||||
|
|
||||||
public class RogueKeys implements KeySetup {
|
public class RogueKeys implements KeySetup {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addKeys(KeyConfig keys)
|
public void addKeys(KeyOpts keys)
|
||||||
{
|
{
|
||||||
keys.add("key.global.quit", "CTRL+SHIFT+Q");
|
keys.add("global.quit", "CTRL+Q");
|
||||||
keys.add("key.global.menu", "CTRL+SHIFT+M");
|
keys.add("global.menu", "CTRL+M");
|
||||||
keys.add("key.global.screenshot", "F2");
|
keys.add("global.screenshot", "F2");
|
||||||
keys.add("key.global.fullscreen", "F11");
|
keys.add("global.fullscreen", "F11");
|
||||||
|
|
||||||
keys.add("key.general.cancel", "ESC");
|
keys.add("general.cancel", "ESC");
|
||||||
keys.add("key.general.confirm", "ENTER");
|
keys.add("general.confirm", "ENTER");
|
||||||
keys.add("key.general.yes", "Y");
|
keys.add("general.yes", "Y");
|
||||||
keys.add("key.general.no", "N");
|
keys.add("general.no", "N");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,123 +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.WorkDir;
|
|
||||||
import mightypork.gamecore.app.BaseApp;
|
|
||||||
import mightypork.gamecore.app.MainLoop;
|
|
||||||
import mightypork.gamecore.gui.Action;
|
|
||||||
import mightypork.gamecore.logging.Log;
|
|
||||||
import mightypork.gamecore.render.Screenshot;
|
|
||||||
import mightypork.gamecore.resources.Res;
|
|
||||||
import mightypork.gamecore.util.Utils;
|
|
||||||
import mightypork.rogue.events.ActionRequest;
|
|
||||||
import mightypork.rogue.events.ActionRequest.RequestType;
|
|
||||||
|
|
||||||
|
|
||||||
public final class RogueMainLoop extends MainLoop implements ActionRequest.Listener {
|
|
||||||
|
|
||||||
public RogueMainLoop(BaseApp app)
|
|
||||||
{
|
|
||||||
super(app);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void requestAction(RequestType request)
|
|
||||||
{
|
|
||||||
switch (request) {
|
|
||||||
case FULLSCREEN:
|
|
||||||
queueTask(taskFullscreen);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SCREENSHOT:
|
|
||||||
queueTask(taskScreenshot);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SHUTDOWN:
|
|
||||||
queueTask(taskShutdown);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Take a screenshot
|
|
||||||
*/
|
|
||||||
private final Action taskScreenshot = new Action() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
Res.getSoundEffect("gui.shutter").play(1);
|
|
||||||
Utils.runAsThread(new TaskTakeScreenshot());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Shutdown the application
|
|
||||||
*/
|
|
||||||
private final Action taskShutdown = new Action() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
shutdown();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Toggle fullscreen
|
|
||||||
*/
|
|
||||||
private final Action taskFullscreen = new Action() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
getDisplay().switchFullscreen();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO factor into gamecore
|
|
||||||
private class TaskTakeScreenshot implements Runnable {
|
|
||||||
|
|
||||||
private final Screenshot scr;
|
|
||||||
|
|
||||||
|
|
||||||
public TaskTakeScreenshot()
|
|
||||||
{
|
|
||||||
scr = getDisplay().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(WorkDir.getDir("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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,14 +2,14 @@ package mightypork.rogue;
|
|||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.resources.ResourceSetup;
|
import mightypork.gamecore.resources.ResourceSetup;
|
||||||
import mightypork.gamecore.resources.audio.SoundBank;
|
import mightypork.gamecore.resources.audio.SoundRegistry;
|
||||||
import mightypork.gamecore.resources.fonts.FontBank;
|
import mightypork.gamecore.resources.fonts.FontRegistry;
|
||||||
import mightypork.gamecore.resources.fonts.Glyphs;
|
import mightypork.gamecore.resources.fonts.Glyphs;
|
||||||
import mightypork.gamecore.resources.fonts.impl.DeferredFont;
|
import mightypork.gamecore.resources.fonts.impl.DeferredFont;
|
||||||
import mightypork.gamecore.resources.textures.FilterMode;
|
import mightypork.gamecore.resources.textures.FilterMode;
|
||||||
import mightypork.gamecore.resources.textures.GLTexture;
|
import mightypork.gamecore.resources.textures.GLTexture;
|
||||||
import mightypork.gamecore.resources.textures.QuadGrid;
|
import mightypork.gamecore.resources.textures.QuadGrid;
|
||||||
import mightypork.gamecore.resources.textures.TextureBank;
|
import mightypork.gamecore.resources.textures.TextureRegistry;
|
||||||
import mightypork.gamecore.resources.textures.WrapMode;
|
import mightypork.gamecore.resources.textures.WrapMode;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ public class RogueResources implements ResourceSetup {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addFonts(FontBank fonts)
|
public void addFonts(FontRegistry fonts)
|
||||||
{
|
{
|
||||||
DeferredFont font;
|
DeferredFont font;
|
||||||
|
|
||||||
@@ -39,14 +39,14 @@ public class RogueResources implements ResourceSetup {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addSounds(SoundBank sounds)
|
public void addSounds(SoundRegistry sounds)
|
||||||
{
|
{
|
||||||
sounds.addEffect("gui.shutter", "/res/audio/shutter.ogg", 1, 1);
|
sounds.addEffect("gui.shutter", "/res/audio/shutter.ogg", 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTextures(TextureBank textures)
|
public void addTextures(TextureRegistry textures)
|
||||||
{
|
{
|
||||||
GLTexture texture;
|
GLTexture texture;
|
||||||
QuadGrid grid;
|
QuadGrid grid;
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package mightypork.rogue;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.gamecore.WorkDir.RouteOpts;
|
||||||
|
import mightypork.gamecore.WorkDir.RouteSetup;
|
||||||
|
|
||||||
|
|
||||||
|
public class RogueRoutes implements RouteSetup {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addRoutes(RouteOpts routeOpts)
|
||||||
|
{
|
||||||
|
routeOpts.addPath("slot1", "saves/slot_1.ion");
|
||||||
|
routeOpts.addPath("slot2", "saves/slot_2.ion");
|
||||||
|
routeOpts.addPath("slot3", "saves/slot_3.ion");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package mightypork.rogue;
|
package mightypork.rogue;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.app.AppModule;
|
import mightypork.gamecore.core.AppModule;
|
||||||
import mightypork.gamecore.gui.events.CrossfadeRequest;
|
import mightypork.gamecore.gui.events.CrossfadeRequest;
|
||||||
import mightypork.gamecore.logging.Log;
|
import mightypork.gamecore.logging.Log;
|
||||||
|
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
package mightypork.rogue.events;
|
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.eventbus.BusEvent;
|
|
||||||
import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request for a global action to be done in the main loop.
|
|
||||||
*
|
|
||||||
* @author MightyPork
|
|
||||||
*/
|
|
||||||
@SingleReceiverEvent
|
|
||||||
public class ActionRequest extends BusEvent<ActionRequest.Listener> {
|
|
||||||
|
|
||||||
private final RequestType type;
|
|
||||||
|
|
||||||
|
|
||||||
public ActionRequest(RequestType request)
|
|
||||||
{
|
|
||||||
type = request;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleBy(Listener handler)
|
|
||||||
{
|
|
||||||
handler.requestAction(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Listener {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform the requested action
|
|
||||||
*
|
|
||||||
* @param request
|
|
||||||
*/
|
|
||||||
void requestAction(RequestType request);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return "ActionRequest(" + type + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum RequestType
|
|
||||||
{
|
|
||||||
FULLSCREEN, SCREENSHOT, SHUTDOWN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-2
@@ -11,12 +11,12 @@ import mightypork.rogue.RogueStateManager.RogueState;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public class GameStateRequest extends BusEvent<RogueStateManager> {
|
public class RogueStateRequest extends BusEvent<RogueStateManager> {
|
||||||
|
|
||||||
final private RogueState requested;
|
final private RogueState requested;
|
||||||
|
|
||||||
|
|
||||||
public GameStateRequest(RogueState requested)
|
public RogueStateRequest(RogueState requested)
|
||||||
{
|
{
|
||||||
this.requested = requested;
|
this.requested = requested;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.rogue.screens;
|
package mightypork.rogue.screens;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.Action;
|
import mightypork.gamecore.gui.Action;
|
||||||
import mightypork.gamecore.gui.AlignX;
|
import mightypork.gamecore.gui.AlignX;
|
||||||
import mightypork.gamecore.gui.components.painters.TextPainter;
|
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.rogue.screens;
|
package mightypork.rogue.screens;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.AlignX;
|
import mightypork.gamecore.gui.AlignX;
|
||||||
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
||||||
import mightypork.gamecore.gui.components.painters.TextPainter;
|
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import mightypork.gamecore.resources.fonts.GLFont;
|
|||||||
import mightypork.gamecore.util.math.color.pal.RGB;
|
import mightypork.gamecore.util.math.color.pal.RGB;
|
||||||
import mightypork.gamecore.util.math.constraints.num.Num;
|
import mightypork.gamecore.util.math.constraints.num.Num;
|
||||||
import mightypork.rogue.RogueStateManager.RogueState;
|
import mightypork.rogue.RogueStateManager.RogueState;
|
||||||
import mightypork.rogue.events.GameStateRequest;
|
import mightypork.rogue.events.RogueStateRequest;
|
||||||
import mightypork.rogue.screens.game.ScreenGame.GScrState;
|
import mightypork.rogue.screens.game.ScreenGame.GScrState;
|
||||||
import mightypork.rogue.world.WorldProvider;
|
import mightypork.rogue.world.WorldProvider;
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ public class DeathLayer extends ScreenLayer {
|
|||||||
@Override
|
@Override
|
||||||
protected void execute()
|
protected void execute()
|
||||||
{
|
{
|
||||||
getEventBus().send(new GameStateRequest(RogueState.MAIN_MENU));
|
getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.rogue.screens.game;
|
package mightypork.rogue.screens.game;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.AlignX;
|
import mightypork.gamecore.gui.AlignX;
|
||||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||||
import mightypork.gamecore.gui.components.layout.FlowColumnLayout;
|
import mightypork.gamecore.gui.components.layout.FlowColumnLayout;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package mightypork.rogue.screens.game;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.Action;
|
import mightypork.gamecore.gui.Action;
|
||||||
import mightypork.gamecore.gui.ActionGroup;
|
import mightypork.gamecore.gui.ActionGroup;
|
||||||
import mightypork.gamecore.gui.screens.LayeredScreen;
|
import mightypork.gamecore.gui.screens.LayeredScreen;
|
||||||
@@ -14,7 +14,7 @@ import mightypork.gamecore.logging.Log;
|
|||||||
import mightypork.gamecore.util.math.color.Color;
|
import mightypork.gamecore.util.math.color.Color;
|
||||||
import mightypork.rogue.Const;
|
import mightypork.rogue.Const;
|
||||||
import mightypork.rogue.RogueStateManager.RogueState;
|
import mightypork.rogue.RogueStateManager.RogueState;
|
||||||
import mightypork.rogue.events.GameStateRequest;
|
import mightypork.rogue.events.RogueStateRequest;
|
||||||
import mightypork.rogue.world.PlayerFacade;
|
import mightypork.rogue.world.PlayerFacade;
|
||||||
import mightypork.rogue.world.WorldProvider;
|
import mightypork.rogue.world.WorldProvider;
|
||||||
import mightypork.rogue.world.events.PlayerKilledListener;
|
import mightypork.rogue.world.events.PlayerKilledListener;
|
||||||
@@ -198,7 +198,7 @@ public class ScreenGame extends LayeredScreen implements PlayerKilledListener {
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
getEventBus().send(new GameStateRequest(RogueState.MAIN_MENU));
|
getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ public class ScreenGame extends LayeredScreen implements PlayerKilledListener {
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
getEventBus().send(new GameStateRequest(RogueState.EXIT));
|
getEventBus().send(new RogueStateRequest(RogueState.EXIT));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.rogue.screens.layout_testing;
|
package mightypork.rogue.screens.layout_testing;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.AlignX;
|
import mightypork.gamecore.gui.AlignX;
|
||||||
import mightypork.gamecore.gui.components.layout.linear.LinearGap;
|
import mightypork.gamecore.gui.components.layout.linear.LinearGap;
|
||||||
import mightypork.gamecore.gui.components.layout.linear.LinearLayout;
|
import mightypork.gamecore.gui.components.layout.linear.LinearLayout;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.rogue.screens.menu;
|
package mightypork.rogue.screens.menu;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.Action;
|
import mightypork.gamecore.gui.Action;
|
||||||
import mightypork.gamecore.gui.AlignX;
|
import mightypork.gamecore.gui.AlignX;
|
||||||
import mightypork.gamecore.gui.components.input.TextButton;
|
import mightypork.gamecore.gui.components.input.TextButton;
|
||||||
@@ -22,7 +22,7 @@ import mightypork.gamecore.util.math.color.pal.PAL16;
|
|||||||
import mightypork.gamecore.util.math.constraints.num.Num;
|
import mightypork.gamecore.util.math.constraints.num.Num;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||||||
import mightypork.rogue.RogueStateManager.RogueState;
|
import mightypork.rogue.RogueStateManager.RogueState;
|
||||||
import mightypork.rogue.events.GameStateRequest;
|
import mightypork.rogue.events.RogueStateRequest;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +84,7 @@ public class ScreenMainMenu extends LayeredScreen {
|
|||||||
@Override
|
@Override
|
||||||
protected void execute()
|
protected void execute()
|
||||||
{
|
{
|
||||||
getEventBus().send(new GameStateRequest(RogueState.SELECT_WORLD));
|
getEventBus().send(new RogueStateRequest(RogueState.SELECT_WORLD));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
rows.add(btn, 2);
|
rows.add(btn, 2);
|
||||||
@@ -112,7 +112,7 @@ public class ScreenMainMenu extends LayeredScreen {
|
|||||||
@Override
|
@Override
|
||||||
protected void execute()
|
protected void execute()
|
||||||
{
|
{
|
||||||
getEventBus().send(new GameStateRequest(RogueState.EXIT));
|
getEventBus().send(new RogueStateRequest(RogueState.EXIT));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
rows.add(btn, 2);
|
rows.add(btn, 2);
|
||||||
@@ -123,7 +123,7 @@ public class ScreenMainMenu extends LayeredScreen {
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
getEventBus().send(new GameStateRequest(RogueState.EXIT));
|
getEventBus().send(new RogueStateRequest(RogueState.EXIT));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package mightypork.rogue.screens.select_world;
|
|||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.WorkDir;
|
import mightypork.gamecore.WorkDir;
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.AlignX;
|
import mightypork.gamecore.gui.AlignX;
|
||||||
import mightypork.gamecore.gui.components.layout.RowLayout;
|
import mightypork.gamecore.gui.components.layout.RowLayout;
|
||||||
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
||||||
@@ -19,7 +19,7 @@ import mightypork.gamecore.util.math.color.pal.PAL16;
|
|||||||
import mightypork.gamecore.util.math.color.pal.RGB;
|
import mightypork.gamecore.util.math.color.pal.RGB;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||||||
import mightypork.rogue.RogueStateManager.RogueState;
|
import mightypork.rogue.RogueStateManager.RogueState;
|
||||||
import mightypork.rogue.events.GameStateRequest;
|
import mightypork.rogue.events.RogueStateRequest;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,13 +72,13 @@ public class ScreenSelectWorld extends LayeredScreen {
|
|||||||
tp.setVPaddingPercent(20);
|
tp.setVPaddingPercent(20);
|
||||||
tp.setShadow(RGB.BLACK_50, tp.height().mul(0.6 / 8D).toVectXY());
|
tp.setShadow(RGB.BLACK_50, tp.height().mul(0.6 / 8D).toVectXY());
|
||||||
|
|
||||||
slot1 = new WorldSlot(root, WorkDir.getFile("save/slot_1.ion"));
|
slot1 = new WorldSlot(root, WorkDir.getFile("slot1"));
|
||||||
rows.add(slot1);
|
rows.add(slot1);
|
||||||
|
|
||||||
slot2 = new WorldSlot(root, WorkDir.getFile("save/slot_2.ion"));
|
slot2 = new WorldSlot(root, WorkDir.getFile("slot2"));
|
||||||
rows.add(slot2);
|
rows.add(slot2);
|
||||||
|
|
||||||
slot3 = new WorldSlot(root, WorkDir.getFile("save/slot_3.ion"));
|
slot3 = new WorldSlot(root, WorkDir.getFile("slot3"));
|
||||||
rows.add(slot3);
|
rows.add(slot3);
|
||||||
|
|
||||||
// escape to quitn from here
|
// escape to quitn from here
|
||||||
@@ -87,7 +87,7 @@ public class ScreenSelectWorld extends LayeredScreen {
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
getEventBus().send(new GameStateRequest(RogueState.MAIN_MENU));
|
getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ public class ScreenSelectWorld extends LayeredScreen {
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
getEventBus().send(new GameStateRequest(RogueState.EXIT));
|
getEventBus().send(new RogueStateRequest(RogueState.EXIT));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package mightypork.rogue.screens.select_world;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import mightypork.gamecore.app.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.gui.Action;
|
import mightypork.gamecore.gui.Action;
|
||||||
import mightypork.gamecore.gui.AlignX;
|
import mightypork.gamecore.gui.AlignX;
|
||||||
import mightypork.gamecore.gui.components.input.TextButton;
|
import mightypork.gamecore.gui.components.input.TextButton;
|
||||||
|
|||||||
Reference in New Issue
Block a user