Refactoring & cleaning

v5stable
ondra 11 years ago
parent cc85d8a9d3
commit f3c6f4f0f5
  1. 6
      src/mightypork/gamecore/audio/SoundBank.java
  2. 4
      src/mightypork/gamecore/audio/SoundSystem.java
  3. 7
      src/mightypork/gamecore/control/AppAccess.java
  4. 16
      src/mightypork/gamecore/control/AppAdapter.java
  5. 13
      src/mightypork/gamecore/control/AppModule.java
  6. 13
      src/mightypork/gamecore/control/AppSubModule.java
  7. 14
      src/mightypork/gamecore/control/BusAccess.java
  8. 6
      src/mightypork/gamecore/control/GameLoop.java
  9. 18
      src/mightypork/gamecore/control/bus/BusAccess.java
  10. 11
      src/mightypork/gamecore/control/bus/clients/BusNode.java
  11. 7
      src/mightypork/gamecore/control/bus/clients/RootBusNode.java
  12. 6
      src/mightypork/gamecore/control/bus/events/KeyEvent.java
  13. 1
      src/mightypork/gamecore/control/bus/events/UpdateEvent.java
  14. 7
      src/mightypork/gamecore/control/interf/NoImpl.java
  15. 2
      src/mightypork/gamecore/gui/renderers/ElementHolder.java
  16. 4
      src/mightypork/gamecore/gui/screens/LayeredScreen.java
  17. 27
      src/mightypork/gamecore/gui/screens/Screen.java
  18. 4
      src/mightypork/gamecore/gui/screens/ScreenLayer.java
  19. 4
      src/mightypork/gamecore/gui/screens/ScreenRegistry.java
  20. 21
      src/mightypork/gamecore/input/InputSystem.java
  21. 6
      src/mightypork/gamecore/input/KeyBinding.java
  22. 6
      src/mightypork/gamecore/input/KeyBindingPool.java
  23. 6
      src/mightypork/gamecore/loading/AsyncResourceLoader.java
  24. 6
      src/mightypork/gamecore/render/DisplaySystem.java
  25. 2
      src/mightypork/gamecore/render/fonts/FontBank.java
  26. 2
      src/mightypork/gamecore/render/textures/TextureBank.java
  27. 48
      src/mightypork/rogue/App.java
  28. 2
      src/mightypork/rogue/MainLoop.java
  29. 2
      src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java
  30. 24
      src/mightypork/rogue/screens/test_bouncyboxes/ScreenTestBouncy.java
  31. 2
      src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java
  32. 14
      src/mightypork/rogue/screens/test_cat_sound/ScreenTestCat.java
  33. 31
      src/mightypork/rogue/screens/test_font/ScreenTestFont.java

@ -23,7 +23,7 @@ public class SoundBank extends AppAdapter {
public SoundBank(AppAccess app) { public SoundBank(AppAccess app) {
super(app); super(app);
if (snd() == null) throw new NullPointerException("SoundSystem cannot be null."); if (getSoundSystem() == null) throw new NullPointerException("SoundSystem cannot be null.");
} }
@ -37,7 +37,7 @@ public class SoundBank extends AppAdapter {
*/ */
public void addEffect(String key, String resource, double pitch, double gain) public void addEffect(String key, String resource, double pitch, double gain)
{ {
effects.put(key, snd().createEffect(resource, pitch, gain)); effects.put(key, getSoundSystem().createEffect(resource, pitch, gain));
} }
@ -53,7 +53,7 @@ public class SoundBank extends AppAdapter {
*/ */
public void addLoop(String key, String resource, double pitch, double gain, double fadeIn, double fadeOut) public void addLoop(String key, String resource, double pitch, double gain, double fadeIn, double fadeOut)
{ {
loops.put(key, snd().createLoop(resource, pitch, gain, fadeIn, fadeOut)); loops.put(key, getSoundSystem().createLoop(resource, pitch, gain, fadeIn, fadeOut));
} }

@ -8,7 +8,7 @@ import java.util.Set;
import mightypork.gamecore.audio.players.EffectPlayer; import mightypork.gamecore.audio.players.EffectPlayer;
import mightypork.gamecore.audio.players.LoopPlayer; import mightypork.gamecore.audio.players.LoopPlayer;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.RootBusNode; import mightypork.gamecore.control.bus.clients.RootBusNode;
import mightypork.gamecore.control.bus.events.ResourceLoadRequest; import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
import mightypork.gamecore.control.interf.Updateable; import mightypork.gamecore.control.interf.Updateable;
import mightypork.utils.math.Calc.Buffers; import mightypork.utils.math.Calc.Buffers;
@ -149,7 +149,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
private DeferredAudio getResource(String res) private DeferredAudio getResource(String res)
{ {
final DeferredAudio a = new DeferredAudio(res); final DeferredAudio a = new DeferredAudio(res);
bus().send(new ResourceLoadRequest(a)); getEventBus().send(new ResourceLoadRequest(a));
if (resources.contains(a)) throw new IllegalArgumentException("Sound resource " + res + " is already registered."); if (resources.contains(a)) throw new IllegalArgumentException("Sound resource " + res + " is already registered.");
resources.add(a); resources.add(a);

@ -2,6 +2,7 @@ package mightypork.gamecore.control;
import mightypork.gamecore.audio.SoundSystem; import mightypork.gamecore.audio.SoundSystem;
import mightypork.gamecore.control.bus.BusAccess;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.render.DisplaySystem; import mightypork.gamecore.render.DisplaySystem;
@ -16,19 +17,19 @@ public interface AppAccess extends BusAccess {
/** /**
* @return sound system * @return sound system
*/ */
abstract SoundSystem snd(); abstract SoundSystem getSoundSystem();
/** /**
* @return input system * @return input system
*/ */
abstract InputSystem input(); abstract InputSystem getInput();
/** /**
* @return display system * @return display system
*/ */
abstract DisplaySystem disp(); abstract DisplaySystem getDisplay();
/** /**

@ -25,30 +25,30 @@ public class AppAdapter implements AppAccess {
@Override @Override
public final SoundSystem snd() public final SoundSystem getSoundSystem()
{ {
return app.snd(); return app.getSoundSystem();
} }
@Override @Override
public final InputSystem input() public final InputSystem getInput()
{ {
return app.input(); return app.getInput();
} }
@Override @Override
public final DisplaySystem disp() public final DisplaySystem getDisplay()
{ {
return app.disp(); return app.getDisplay();
} }
@Override @Override
public final EventBus bus() public final EventBus getEventBus()
{ {
return app.bus(); return app.getEventBus();
} }

@ -2,6 +2,7 @@ package mightypork.gamecore.control;
import mightypork.gamecore.audio.SoundSystem; import mightypork.gamecore.audio.SoundSystem;
import mightypork.gamecore.control.bus.clients.RootBusNode;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.render.DisplaySystem; import mightypork.gamecore.render.DisplaySystem;
@ -25,23 +26,23 @@ public abstract class AppModule extends RootBusNode implements AppAccess {
@Override @Override
public final SoundSystem snd() public final SoundSystem getSoundSystem()
{ {
return app.snd(); return app.getSoundSystem();
} }
@Override @Override
public final InputSystem input() public final InputSystem getInput()
{ {
return app.input(); return app.getInput();
} }
@Override @Override
public final DisplaySystem disp() public final DisplaySystem getDisplay()
{ {
return app.disp(); return app.getDisplay();
} }

@ -2,6 +2,7 @@ package mightypork.gamecore.control;
import mightypork.gamecore.audio.SoundSystem; import mightypork.gamecore.audio.SoundSystem;
import mightypork.gamecore.control.bus.clients.BusNode;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.render.DisplaySystem; import mightypork.gamecore.render.DisplaySystem;
@ -25,23 +26,23 @@ public abstract class AppSubModule extends BusNode implements AppAccess {
@Override @Override
public final SoundSystem snd() public final SoundSystem getSoundSystem()
{ {
return app.snd(); return app.getSoundSystem();
} }
@Override @Override
public final InputSystem input() public final InputSystem getInput()
{ {
return app.input(); return app.getInput();
} }
@Override @Override
public final DisplaySystem disp() public final DisplaySystem getDisplay()
{ {
return app.disp(); return app.getDisplay();
} }

@ -1,14 +0,0 @@
package mightypork.gamecore.control;
import mightypork.gamecore.control.bus.EventBus;
public interface BusAccess {
/**
* @return event bus
*/
EventBus bus();
}

@ -46,9 +46,9 @@ public abstract class GameLoop extends AppModule implements MainLoopTaskRequest.
timer = new TimerDelta(); timer = new TimerDelta();
while (running) { while (running) {
disp().beginFrame(); getDisplay().beginFrame();
bus().send(new UpdateEvent(timer.getDelta())); getEventBus().send(new UpdateEvent(timer.getDelta()));
Runnable r; Runnable r;
while ((r = taskQueue.poll()) != null) { while ((r = taskQueue.poll()) != null) {
@ -61,7 +61,7 @@ public abstract class GameLoop extends AppModule implements MainLoopTaskRequest.
afterRender(); afterRender();
disp().endFrame(); getDisplay().endFrame();
} }
} }

@ -0,0 +1,18 @@
package mightypork.gamecore.control.bus;
/**
* Access to an {@link EventBus} instance
*
* @author MightyPork
*/
public interface BusAccess {
/**
* @return event bus
*/
EventBus getEventBus();
}

@ -1,13 +1,12 @@
package mightypork.gamecore.control; package mightypork.gamecore.control.bus.clients;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import mightypork.gamecore.control.bus.BusAccess;
import mightypork.gamecore.control.bus.EventBus; import mightypork.gamecore.control.bus.EventBus;
import mightypork.gamecore.control.bus.clients.DelegatingClient;
import mightypork.gamecore.control.bus.clients.ToggleableClient;
/** /**
@ -62,7 +61,7 @@ public abstract class BusNode implements BusAccess, DelegatingClient, Toggleable
throw new IllegalArgumentException("Cannot nest RootBusNode."); throw new IllegalArgumentException("Cannot nest RootBusNode.");
} }
if (bus().isClientValid(client)) { if (getEventBus().isClientValid(client)) {
clients.add(client); clients.add(client);
} }
} }
@ -104,9 +103,9 @@ public abstract class BusNode implements BusAccess, DelegatingClient, Toggleable
@Override @Override
public final EventBus bus() public final EventBus getEventBus()
{ {
return busAccess.bus(); return busAccess.getEventBus();
} }
} }

@ -1,5 +1,6 @@
package mightypork.gamecore.control; package mightypork.gamecore.control.bus.clients;
import mightypork.gamecore.control.bus.BusAccess;
import mightypork.gamecore.control.interf.Destroyable; import mightypork.gamecore.control.interf.Destroyable;
@ -13,7 +14,7 @@ public abstract class RootBusNode extends BusNode implements Destroyable {
public RootBusNode(BusAccess busAccess) { public RootBusNode(BusAccess busAccess) {
super(busAccess); super(busAccess);
bus().subscribe(this); getEventBus().subscribe(this);
} }
@ -22,7 +23,7 @@ public abstract class RootBusNode extends BusNode implements Destroyable {
{ {
deinit(); deinit();
bus().unsubscribe(this); getEventBus().unsubscribe(this);
} }

@ -9,14 +9,14 @@ import org.lwjgl.input.Keyboard;
* *
* @author MightyPork * @author MightyPork
*/ */
public class KeyboardEvent implements Event<KeyboardEvent.Listener> { public class KeyEvent implements Event<KeyEvent.Listener> {
private final int key; private final int key;
private final boolean down; private final boolean down;
private final char c; private final char c;
public KeyboardEvent(int key, char c, boolean down) { public KeyEvent(int key, char c, boolean down) {
this.key = key; this.key = key;
this.c = c; this.c = c;
this.down = down; this.down = down;
@ -72,7 +72,7 @@ public class KeyboardEvent implements Event<KeyboardEvent.Listener> {
* *
* @param event event * @param event event
*/ */
void receive(KeyboardEvent event); void receive(KeyEvent event);
} }

@ -12,7 +12,6 @@ import mightypork.gamecore.control.interf.Updateable;
* @author MightyPork * @author MightyPork
*/ */
// sending via queue would hog the bus // sending via queue would hog the bus
@UnloggedEvent @UnloggedEvent
@ImmediateEvent @ImmediateEvent
public class UpdateEvent implements Event<Updateable> { public class UpdateEvent implements Event<Updateable> {

@ -1,11 +1,16 @@
package mightypork.gamecore.control.interf; package mightypork.gamecore.control.interf;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Documented @Documented
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@Target(value={ElementType.METHOD})
public @interface NoImpl { public @interface NoImpl {
//
} }

@ -4,8 +4,8 @@ package mightypork.gamecore.gui.renderers;
import java.util.LinkedList; import java.util.LinkedList;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.BusNode;
import mightypork.gamecore.control.bus.EventBus; import mightypork.gamecore.control.bus.EventBus;
import mightypork.gamecore.control.bus.clients.BusNode;
import mightypork.utils.math.constraints.RectConstraint; import mightypork.utils.math.constraints.RectConstraint;
import mightypork.utils.math.coord.Rect; import mightypork.utils.math.coord.Rect;

@ -33,8 +33,8 @@ public abstract class LayeredScreen extends Screen {
*/ */
protected final void addLayer(ScreenLayer layer) protected final void addLayer(ScreenLayer layer)
{ {
this.layers.add(layer); // will be rendered from last to first this.layers.add(layer);
addChildClient(layer); // connect to bus addChildClient(layer);
} }

@ -4,6 +4,7 @@ package mightypork.gamecore.gui.screens;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.AppSubModule; import mightypork.gamecore.control.AppSubModule;
import mightypork.gamecore.control.bus.events.ScreenChangeEvent; import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
import mightypork.gamecore.control.interf.NoImpl;
import mightypork.gamecore.gui.renderers.Renderable; import mightypork.gamecore.gui.renderers.Renderable;
import mightypork.gamecore.input.KeyBinder; import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool; import mightypork.gamecore.input.KeyBindingPool;
@ -79,22 +80,24 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
} }
/**
* Clean up before screen is destroyed.
*/
protected abstract void deinitScreen();
/** /**
* Called when the screen becomes active * Called when the screen becomes active
*/ */
protected abstract void onScreenEnter(); @NoImpl
protected void onScreenEnter()
{
//
}
/** /**
* Called when the screen is no longer active * Called when the screen is no longer active
*/ */
protected abstract void onScreenLeave(); @NoImpl
protected void onScreenLeave()
{
//
}
/** /**
@ -102,9 +105,10 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
* *
* @param size screen size * @param size screen size
*/ */
@NoImpl
protected void onSizeChanged(Coord size) protected void onSizeChanged(Coord size)
{ {
// no impl //
} }
@ -137,7 +141,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
@Override @Override
public final Rect getRect() public final Rect getRect()
{ {
return disp().getRect(); return getDisplay().getRect();
} }
@ -154,5 +158,8 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
} }
/**
* @return screen identifier to be used for requests.
*/
public abstract String getId(); public abstract String getId();
} }

@ -44,14 +44,14 @@ public abstract class ScreenLayer extends AppSubModule implements Renderable, Re
} }
protected Screen screen() protected final Screen getScreen()
{ {
return screen; return screen;
} }
@Override @Override
public Rect getRect() public final Rect getRect()
{ {
return screen.getRect(); return screen.getRect();
} }

@ -6,6 +6,7 @@ import java.util.HashMap;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.AppModule; import mightypork.gamecore.control.AppModule;
import mightypork.gamecore.control.bus.events.ScreenRequestEvent; import mightypork.gamecore.control.bus.events.ScreenRequestEvent;
import mightypork.gamecore.control.interf.NoImpl;
import mightypork.gamecore.gui.renderers.Renderable; import mightypork.gamecore.gui.renderers.Renderable;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
@ -52,9 +53,10 @@ public class ScreenRegistry extends AppModule implements ScreenRequestEvent.List
@Override @Override
@NoImpl
protected void deinit() protected void deinit()
{ {
// no impl //
} }
} }

@ -2,8 +2,8 @@ package mightypork.gamecore.input;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.RootBusNode; import mightypork.gamecore.control.bus.clients.RootBusNode;
import mightypork.gamecore.control.bus.events.KeyboardEvent; import mightypork.gamecore.control.bus.events.KeyEvent;
import mightypork.gamecore.control.bus.events.MouseButtonEvent; import mightypork.gamecore.control.bus.events.MouseButtonEvent;
import mightypork.gamecore.control.bus.events.MouseMotionEvent; import mightypork.gamecore.control.bus.events.MouseMotionEvent;
import mightypork.gamecore.control.interf.Updateable; import mightypork.gamecore.control.interf.Updateable;
@ -92,14 +92,16 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
wasMouse = true; wasMouse = true;
} }
if (wasMouse && !moveSum.isZero()) bus().send(new MouseMotionEvent(lastPos, moveSum)); if (wasMouse && !moveSum.isZero()) {
getEventBus().send(new MouseMotionEvent(lastPos, moveSum));
}
while (Keyboard.next()) { while (Keyboard.next()) {
onKeyEvent(); onKeyEvent();
} }
if (Display.isCloseRequested()) { if (Display.isCloseRequested()) {
bus().send(new ActionRequest(RequestType.SHUTDOWN)); getEventBus().send(new ActionRequest(RequestType.SHUTDOWN));
} }
} }
@ -118,7 +120,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
} }
if (button != -1 || wheeld != 0) { if (button != -1 || wheeld != 0) {
bus().send(new MouseButtonEvent(pos, button, down, wheeld)); getEventBus().send(new MouseButtonEvent(pos, button, down, wheeld));
} }
moveSum.add_ip(move); moveSum.add_ip(move);
@ -132,7 +134,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
final boolean down = Keyboard.getEventKeyState(); final boolean down = Keyboard.getEventKeyState();
final char c = Keyboard.getEventCharacter(); final char c = Keyboard.getEventCharacter();
bus().send(new KeyboardEvent(key, c, down)); getEventBus().send(new KeyEvent(key, c, down));
} }
@ -155,11 +157,17 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
} }
/**
* Trap mouse cursor in the window
*
* @param grab true to grab
*/
public void grabMouse(boolean grab) public void grabMouse(boolean grab)
{ {
Mouse.setGrabbed(grab); Mouse.setGrabbed(grab);
} }
/** Horizontal mouse position */
public static final NumberConstraint mouseX = new NumberConstraint() { public static final NumberConstraint mouseX = new NumberConstraint() {
@Override @Override
@ -169,6 +177,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
} }
}; };
/** Vertical mouse position */
public static final NumberConstraint mouseY = new NumberConstraint() { public static final NumberConstraint mouseY = new NumberConstraint() {
@Override @Override

@ -1,7 +1,7 @@
package mightypork.gamecore.input; package mightypork.gamecore.input;
import mightypork.gamecore.control.bus.events.KeyboardEvent; import mightypork.gamecore.control.bus.events.KeyEvent;
/** /**
@ -9,7 +9,7 @@ import mightypork.gamecore.control.bus.events.KeyboardEvent;
* *
* @author MightyPork * @author MightyPork
*/ */
public class KeyBinding implements KeyboardEvent.Listener { public class KeyBinding implements KeyEvent.Listener {
private final KeyStroke keystroke; private final KeyStroke keystroke;
private Runnable handler; private Runnable handler;
@ -50,7 +50,7 @@ public class KeyBinding implements KeyboardEvent.Listener {
@Override @Override
public void receive(KeyboardEvent event) public void receive(KeyEvent event)
{ {
// ignore unrelated events // ignore unrelated events
if (!keystroke.getKeys().contains(event.getKey())) return; if (!keystroke.getKeys().contains(event.getKey())) return;

@ -5,7 +5,7 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import mightypork.gamecore.control.bus.events.KeyboardEvent; import mightypork.gamecore.control.bus.events.KeyEvent;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
@ -14,7 +14,7 @@ import mightypork.utils.logging.Log;
* *
* @author MightyPork * @author MightyPork
*/ */
public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener { public class KeyBindingPool implements KeyBinder, KeyEvent.Listener {
private final Set<KeyBinding> bindings = new HashSet<KeyBinding>(); private final Set<KeyBinding> bindings = new HashSet<KeyBinding>();
@ -61,7 +61,7 @@ public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener {
@Override @Override
public void receive(KeyboardEvent event) public void receive(KeyEvent event)
{ {
for (final KeyBinding kb : bindings) { for (final KeyBinding kb : bindings) {
kb.receive(event); kb.receive(event);

@ -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.control.BusAccess; import mightypork.gamecore.control.bus.BusAccess;
import mightypork.gamecore.control.bus.events.MainLoopTaskRequest; import mightypork.gamecore.control.bus.events.MainLoopTaskRequest;
import mightypork.gamecore.control.bus.events.ResourceLoadRequest; import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
import mightypork.gamecore.control.interf.Destroyable; import mightypork.gamecore.control.interf.Destroyable;
@ -34,7 +34,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
public AsyncResourceLoader(BusAccess app) { public AsyncResourceLoader(BusAccess app) {
super("Deferred loader"); super("Deferred loader");
this.app = app; this.app = app;
app.bus().subscribe(this); app.getEventBus().subscribe(this);
} }
@ -66,7 +66,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
Log.f3("<LOADER> Delegating to main thread:\n " + Log.str(def)); Log.f3("<LOADER> Delegating to main thread:\n " + Log.str(def));
app.bus().send(new MainLoopTaskRequest(new Runnable() { app.getEventBus().send(new MainLoopTaskRequest(new Runnable() {
@Override @Override
public void run() public void run()

@ -6,7 +6,7 @@ import static org.lwjgl.opengl.GL11.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.RootBusNode; import mightypork.gamecore.control.bus.clients.RootBusNode;
import mightypork.gamecore.control.bus.events.ScreenChangeEvent; import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
import mightypork.gamecore.control.timing.FpsMeter; import mightypork.gamecore.control.timing.FpsMeter;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
@ -89,7 +89,7 @@ public class DisplaySystem extends RootBusNode implements RectConstraint {
Display.update(); Display.update();
} }
bus().send(new ScreenChangeEvent(true, Display.isFullscreen(), getSize())); getEventBus().send(new ScreenChangeEvent(true, Display.isFullscreen(), 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);
@ -174,7 +174,7 @@ public class DisplaySystem extends RootBusNode implements RectConstraint {
{ {
// handle resize // handle resize
if (Display.wasResized()) { if (Display.wasResized()) {
bus().send(new ScreenChangeEvent(false, Display.isFullscreen(), getSize())); getEventBus().send(new ScreenChangeEvent(false, Display.isFullscreen(), getSize()));
} }
glLoadIdentity(); glLoadIdentity();

@ -36,7 +36,7 @@ public class FontBank extends AppAdapter {
*/ */
public void loadFont(String key, DeferredFont font) public void loadFont(String key, DeferredFont font)
{ {
bus().send(new ResourceLoadRequest(font)); getEventBus().send(new ResourceLoadRequest(font));
fonts.put(key, font); fonts.put(key, font);
} }

@ -58,7 +58,7 @@ public class TextureBank extends AppAdapter {
tx.setFilter(filter_min, filter_mag); tx.setFilter(filter_min, filter_mag);
tx.setWrap(wrap); tx.setWrap(wrap);
bus().send(new ResourceLoadRequest(tx)); getEventBus().send(new ResourceLoadRequest(tx));
textures.put(key, tx); textures.put(key, tx);
lastTx = tx; lastTx = tx;

@ -44,7 +44,7 @@ public class App implements AppAccess {
// modules // modules
private InputSystem inputSystem; private InputSystem inputSystem;
private DisplaySystem displaySystem; private DisplaySystem displaySystem;
private static SoundSystem soundSystem; private SoundSystem soundSystem;
private EventBus eventBus; private EventBus eventBus;
private GameLoop mainLoop; private GameLoop mainLoop;
private ScreenRegistry screens; private ScreenRegistry screens;
@ -108,9 +108,9 @@ public class App implements AppAccess {
{ {
Log.i("Shutting down subsystems..."); Log.i("Shutting down subsystems...");
if (bus() != null) { if (getEventBus() != null) {
bus().send(new DestroyEvent()); getEventBus().send(new DestroyEvent());
bus().destroy(); getEventBus().destroy();
} }
Log.i("Terminating..."); Log.i("Terminating...");
@ -209,20 +209,20 @@ public class App implements AppAccess {
Log.f3("Registering channels..."); Log.f3("Registering channels...");
// framework events // framework events
bus().addChannel(DestroyEvent.class, Destroyable.class); getEventBus().addChannel(DestroyEvent.class, Destroyable.class);
bus().addChannel(UpdateEvent.class, Updateable.class); getEventBus().addChannel(UpdateEvent.class, Updateable.class);
// input events // input events
bus().addChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class); getEventBus().addChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class);
bus().addChannel(KeyboardEvent.class, KeyboardEvent.Listener.class); getEventBus().addChannel(KeyEvent.class, KeyEvent.Listener.class);
bus().addChannel(MouseMotionEvent.class, MouseMotionEvent.Listener.class); getEventBus().addChannel(MouseMotionEvent.class, MouseMotionEvent.Listener.class);
bus().addChannel(MouseButtonEvent.class, MouseButtonEvent.Listener.class); getEventBus().addChannel(MouseButtonEvent.class, MouseButtonEvent.Listener.class);
// control events // control events
bus().addChannel(ScreenRequestEvent.class, ScreenRequestEvent.Listener.class); getEventBus().addChannel(ScreenRequestEvent.class, ScreenRequestEvent.Listener.class);
bus().addChannel(ResourceLoadRequest.class, ResourceLoadRequest.Listener.class); getEventBus().addChannel(ResourceLoadRequest.class, ResourceLoadRequest.Listener.class);
bus().addChannel(ActionRequest.class, ActionRequest.Listener.class); getEventBus().addChannel(ActionRequest.class, ActionRequest.Listener.class);
bus().addChannel(MainLoopTaskRequest.class, MainLoopTaskRequest.Listener.class); getEventBus().addChannel(MainLoopTaskRequest.class, MainLoopTaskRequest.Listener.class);
} }
@ -231,32 +231,32 @@ public class App implements AppAccess {
Log.f3("Setting up hot keys..."); Log.f3("Setting up hot keys...");
// Go fullscreen // Go fullscreen
input().bindKeyStroke(new KeyStroke(Keys.KEY_F11), new Runnable() { getInput().bindKeyStroke(new KeyStroke(Keys.KEY_F11), new Runnable() {
@Override @Override
public void run() public void run()
{ {
bus().send(new ActionRequest(RequestType.FULLSCREEN)); getEventBus().send(new ActionRequest(RequestType.FULLSCREEN));
} }
}); });
// Take screenshot // Take screenshot
input().bindKeyStroke(new KeyStroke(Keys.KEY_F2), new Runnable() { getInput().bindKeyStroke(new KeyStroke(Keys.KEY_F2), new Runnable() {
@Override @Override
public void run() public void run()
{ {
bus().send(new ActionRequest(RequestType.SCREENSHOT)); getEventBus().send(new ActionRequest(RequestType.SCREENSHOT));
} }
}); });
// Exit // Exit
input().bindKeyStroke(new KeyStroke(Keys.KEY_LCONTROL, Keys.KEY_Q), new Runnable() { getInput().bindKeyStroke(new KeyStroke(Keys.KEY_LCONTROL, Keys.KEY_Q), new Runnable() {
@Override @Override
public void run() public void run()
{ {
bus().send(new ActionRequest(RequestType.SHUTDOWN)); getEventBus().send(new ActionRequest(RequestType.SHUTDOWN));
} }
}); });
} }
@ -323,7 +323,7 @@ public class App implements AppAccess {
* @return sound system of the running instance * @return sound system of the running instance
*/ */
@Override @Override
public SoundSystem snd() public SoundSystem getSoundSystem()
{ {
return soundSystem; return soundSystem;
} }
@ -333,7 +333,7 @@ public class App implements AppAccess {
* @return input system of the running instance * @return input system of the running instance
*/ */
@Override @Override
public InputSystem input() public InputSystem getInput()
{ {
return inputSystem; return inputSystem;
} }
@ -343,7 +343,7 @@ public class App implements AppAccess {
* @return display system of the running instance * @return display system of the running instance
*/ */
@Override @Override
public DisplaySystem disp() public DisplaySystem getDisplay()
{ {
return displaySystem; return displaySystem;
} }
@ -353,7 +353,7 @@ public class App implements AppAccess {
* @return event bus * @return event bus
*/ */
@Override @Override
public EventBus bus() public EventBus getEventBus()
{ {
return eventBus; return eventBus;
} }

@ -60,7 +60,7 @@ public class MainLoop extends GameLoop implements ActionRequest.Listener {
@Override @Override
public void execute() public void execute()
{ {
disp().switchFullscreen(); getDisplay().switchFullscreen();
} }
}; };
} }

@ -60,7 +60,7 @@ public class LayerBouncyBoxes extends ScreenLayer {
@Override @Override
public String getText() public String getText()
{ {
return "Running at " + disp().getFps() + " fps!"; return "Running at " + getDisplay().getFps() + " fps!";
} }
}); });

@ -25,33 +25,11 @@ public class ScreenTestBouncy extends LayeredScreen {
@Override @Override
public void run() public void run()
{ {
bus().send(new ScreenRequestEvent("test.cat")); getEventBus().send(new ScreenRequestEvent("test.cat"));
} }
}); });
} }
@Override
protected void deinitScreen()
{
// no impl
}
@Override
protected void onScreenEnter()
{
// no impl
}
@Override
protected void onScreenLeave()
{
// no impl
}
@Override @Override
public String getId() public String getId()
{ {

@ -97,7 +97,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
public void render() public void render()
{ {
cat.render(); cat.render();
text.render(disp().getFps()+" fps"); text.render(getDisplay().getFps()+" fps");
} }
} }

@ -26,8 +26,8 @@ public class ScreenTestCat extends LayeredScreen {
@Override @Override
public void run() public void run()
{ {
snd().fadeOutAllLoops(); getSoundSystem().fadeOutAllLoops();
bus().sendDelayed(new ActionRequest(RequestType.SHUTDOWN), 3); getEventBus().sendDelayed(new ActionRequest(RequestType.SHUTDOWN), 3);
} }
}); });
@ -36,22 +36,16 @@ public class ScreenTestCat extends LayeredScreen {
@Override @Override
public void run() public void run()
{ {
bus().send(new ScreenRequestEvent("test.bouncy")); getEventBus().send(new ScreenRequestEvent("test.bouncy"));
} }
}); });
} }
@Override
protected void deinitScreen()
{
}
@Override @Override
protected void onScreenEnter() protected void onScreenEnter()
{ {
snd().fadeOutAllLoops(); getSoundSystem().fadeOutAllLoops();
Res.getLoop("test.wilderness").fadeIn(); Res.getLoop("test.wilderness").fadeIn();
} }

@ -21,27 +21,6 @@ public class ScreenTestFont extends Screen {
} }
@Override
protected void deinitScreen()
{
//
}
@Override
protected void onScreenEnter()
{
//
}
@Override
protected void onScreenLeave()
{
//
}
@Override @Override
protected void renderScreen() protected void renderScreen()
{ {
@ -53,16 +32,6 @@ public class ScreenTestFont extends Screen {
final Coord origin = getRect().getCenter().sub(space.half()); final Coord origin = getRect().getCenter().sub(space.half());
fr.draw(str, origin, height, RGB.GREEN); fr.draw(str, origin, height, RGB.GREEN);
// final GLFont font = Res.getFont("");
//
// final String s = "It works!";
// final double scale = getRect().height() / 50D;
// Render.pushState();
// Render.translate(getRect().getCenter().sub(font.getNeededSpace(s).mul(scale).half()));
// Render.scale(new Coord(scale));
// font.draw("It works!");
// Render.popState();
} }

Loading…
Cancel
Save