almost works

master
Ondřej Hruška 10 years ago
parent dbc32c4d0a
commit 92056f3418
  1. 20
      src/mightypork/gamecore/core/App.java
  2. 5
      src/mightypork/gamecore/core/events/ShutdownEvent.java
  3. 1
      src/mightypork/gamecore/core/init/InitTask.java
  4. 2
      src/mightypork/gamecore/core/init/InitTaskDisplay.java
  5. 2
      src/mightypork/gamecore/core/init/InitTaskMainLoop.java
  6. 2
      src/mightypork/gamecore/core/init/InitTaskResources.java
  7. 9
      src/mightypork/gamecore/core/plugins/screenshot/InitTaskPluginScreenshot.java
  8. 5
      src/mightypork/gamecore/core/plugins/screenshot/ScreenshotPlugin.java
  9. 6
      src/mightypork/gamecore/core/plugins/screenshot/ScreenshotRequest.java
  10. 29
      src/mightypork/gamecore/graphics/GraphicsModule.java
  11. 2
      src/mightypork/gamecore/input/KeyStroke.java
  12. 2
      src/mightypork/gamecore/input/Keys.java

@ -10,6 +10,7 @@ import mightypork.gamecore.core.events.ShutdownEvent;
import mightypork.gamecore.core.init.InitTask; import mightypork.gamecore.core.init.InitTask;
import mightypork.gamecore.core.plugins.AppPlugin; import mightypork.gamecore.core.plugins.AppPlugin;
import mightypork.gamecore.graphics.GraphicsModule; import mightypork.gamecore.graphics.GraphicsModule;
import mightypork.gamecore.graphics.Renderable;
import mightypork.gamecore.input.InputModule; import mightypork.gamecore.input.InputModule;
import mightypork.utils.annotations.Stub; import mightypork.utils.annotations.Stub;
import mightypork.utils.eventbus.EventBus; import mightypork.utils.eventbus.EventBus;
@ -41,6 +42,8 @@ public class App extends BusNode {
/** The used main loop instance */ /** The used main loop instance */
protected MainLoop mainLoop; protected MainLoop mainLoop;
private Renderable mainRenderable;
/** /**
* Create an app with given backend. * Create an app with given backend.
@ -78,10 +81,6 @@ public class App extends BusNode {
*/ */
public void addPlugin(AppPlugin plugin) public void addPlugin(AppPlugin plugin)
{ {
if (started) {
throw new IllegalStateException("App already started, cannot add plugins.");
}
// attach to event bus // attach to event bus
plugins.add(plugin); plugins.add(plugin);
plugin.bind(this); plugin.bind(this);
@ -112,6 +111,18 @@ public class App extends BusNode {
public void setMainLoop(MainLoop loop) public void setMainLoop(MainLoop loop)
{ {
this.mainLoop = loop; this.mainLoop = loop;
bus().subscribe(loop); // ?
}
/**
* Set the main renderable
*
* @param renderable the main renderable
*/
public void setMainRenderable(Renderable renderable)
{
this.mainRenderable = renderable;
} }
@ -146,6 +157,7 @@ public class App extends BusNode {
} }
Log.i("Starting main loop..."); Log.i("Starting main loop...");
mainLoop.setRootRenderable(mainRenderable);
mainLoop.start(); mainLoop.start();
} }

@ -1,6 +1,7 @@
package mightypork.gamecore.core.events; package mightypork.gamecore.core.events;
import mightypork.gamecore.core.App;
import mightypork.utils.eventbus.BusEvent; import mightypork.utils.eventbus.BusEvent;
import mightypork.utils.eventbus.EventBus; import mightypork.utils.eventbus.EventBus;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
@ -42,7 +43,9 @@ public class ShutdownEvent extends BusEvent<ShutdownListener> {
{ {
if (!isConsumed()) { if (!isConsumed()) {
Log.i("Shutting down..."); Log.i("Shutting down...");
shutdownTask.run();
App.bus().send(new MainLoopRequest(shutdownTask, true));
} else { } else {
Log.i("Shutdown aborted."); Log.i("Shutdown aborted.");
} }

@ -118,6 +118,7 @@ public abstract class InitTask {
// resolve task order // resolve task order
int addedThisIteration = 0; int addedThisIteration = 0;
do { do {
addedThisIteration = 0;
for (final Iterator<InitTask> i = remaining.iterator(); i.hasNext();) { for (final Iterator<InitTask> i = remaining.iterator(); i.hasNext();) {
final InitTask task = i.next(); final InitTask task = i.next();

@ -84,6 +84,8 @@ public class InitTaskDisplay extends InitTask {
gfx.setTargetFps(fps); gfx.setTargetFps(fps);
if (fullscreen) gfx.setFullscreen(true); if (fullscreen) gfx.setFullscreen(true);
gfx.createDisplay();
} }

@ -35,6 +35,6 @@ public abstract class InitTaskMainLoop extends InitTask {
@Override @Override
public String getName() public String getName()
{ {
return "resource_loader"; return "main_loop";
} }
} }

@ -29,6 +29,6 @@ public abstract class InitTaskResources extends InitTask implements ResourceInit
@Override @Override
public String[] getDependencies() public String[] getDependencies()
{ {
return new String[] { "resource_loader" }; return new String[] { "resource_loader", "main_loop" };
} }
} }

@ -2,6 +2,7 @@ package mightypork.gamecore.core.plugins.screenshot;
import mightypork.gamecore.core.init.InitTask; import mightypork.gamecore.core.init.InitTask;
import mightypork.gamecore.core.plugins.AppPlugin;
import mightypork.utils.files.WorkDir; import mightypork.utils.files.WorkDir;
@ -50,7 +51,13 @@ public class InitTaskPluginScreenshot extends InitTask {
public void run() public void run()
{ {
WorkDir.addPath("_screenshot_dir", screenshotDir); WorkDir.addPath("_screenshot_dir", screenshotDir);
app.addPlugin(new ScreenshotPlugin()); app.addPlugin(getPluginImpl());
}
protected AppPlugin getPluginImpl()
{
return new ScreenshotPlugin();
} }

@ -14,12 +14,13 @@ import mightypork.utils.Support;
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
public class ScreenshotPlugin extends AppPlugin { public class ScreenshotPlugin extends AppPlugin implements ScreenshotRequestListener {
/** /**
* Take screenshot. Called by the trigger event. * Take screenshot. Called by the trigger event.
*/ */
void takeScreenshot() @Override
public void onScreenshotRequest()
{ {
App.bus().send(new MainLoopRequest(new Runnable() { App.bus().send(new MainLoopRequest(new Runnable() {

@ -11,12 +11,12 @@ import mightypork.utils.eventbus.events.flags.SingleReceiverEvent;
* @author MightyPork * @author MightyPork
*/ */
@SingleReceiverEvent @SingleReceiverEvent
public class ScreenshotRequest extends BusEvent<ScreenshotPlugin> { public class ScreenshotRequest extends BusEvent<ScreenshotRequestListener> {
@Override @Override
protected void handleBy(ScreenshotPlugin handler) protected void handleBy(ScreenshotRequestListener handler)
{ {
handler.takeScreenshot(); handler.onScreenshotRequest();
} }
} }

@ -267,7 +267,7 @@ public abstract class GraphicsModule extends BackendModule {
/** /**
* Get backend-flavoured deferred texture. This should support PNG images. * Get backend-flavoured deferred PNG texture.
* *
* @param path path to texture * @param path path to texture
* @return the deferred font * @return the deferred font
@ -276,7 +276,7 @@ public abstract class GraphicsModule extends BackendModule {
/** /**
* Get backend-flavoured deferred font. This should support TTF fonts. * Get backend-flavoured deferred TTF font.
* *
* @param path path to font, or font name in the system * @param path path to font, or font name in the system
* @return the deferred font * @return the deferred font
@ -284,6 +284,25 @@ public abstract class GraphicsModule extends BackendModule {
public abstract DeferredFont createFontResource(String path); public abstract DeferredFont createFontResource(String path);
/**
* Get backend-flavoured deferred TTF font.
*
* @param path path to font, or font name in the system
* @param chars chars that should be supported
* @param size font size used when rendering the font to a backing texture.
* For bitmap fonts, the actual font height.
* @return the deferred font
*/
public DeferredFont createFont(String path, String chars, double size)
{
final DeferredFont font = createFontResource(path);
font.setChars(chars);
font.setSize(size);
return font;
}
/** /**
* Set target fps (for syncing in endFrame() call).<br> * Set target fps (for syncing in endFrame() call).<br>
* With vsync enabled, the target fps may not be met. * With vsync enabled, the target fps may not be met.
@ -416,4 +435,10 @@ public abstract class GraphicsModule extends BackendModule {
* @return screen height * @return screen height
*/ */
public abstract int getHeight(); public abstract int getHeight();
/**
* Create the display (window) based on current settings.
*/
public abstract void createDisplay();
} }

@ -60,7 +60,7 @@ public class KeyStroke {
*/ */
public boolean isDown() public boolean isDown()
{ {
return key.isDown() && (Keys.getActiveMod() == mod); return key.isDown() && (Keys.getActiveMods() == mod);
} }

@ -346,7 +346,7 @@ public class Keys {
* *
* @return active mod mask (mod bits ored) * @return active mod mask (mod bits ored)
*/ */
public static int getActiveMod() public static int getActiveMods()
{ {
int mods = 0; int mods = 0;

Loading…
Cancel
Save