Refactoring & cleaning
This commit is contained in:
@@ -23,7 +23,7 @@ public class SoundBank extends AppAdapter {
|
||||
|
||||
public SoundBank(AppAccess 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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.LoopPlayer;
|
||||
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.interf.Updateable;
|
||||
import mightypork.utils.math.Calc.Buffers;
|
||||
@@ -149,7 +149,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
|
||||
private DeferredAudio getResource(String 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.");
|
||||
resources.add(a);
|
||||
|
||||
@@ -2,6 +2,7 @@ package mightypork.gamecore.control;
|
||||
|
||||
|
||||
import mightypork.gamecore.audio.SoundSystem;
|
||||
import mightypork.gamecore.control.bus.BusAccess;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
|
||||
@@ -16,19 +17,19 @@ public interface AppAccess extends BusAccess {
|
||||
/**
|
||||
* @return sound system
|
||||
*/
|
||||
abstract SoundSystem snd();
|
||||
abstract SoundSystem getSoundSystem();
|
||||
|
||||
|
||||
/**
|
||||
* @return input system
|
||||
*/
|
||||
abstract InputSystem input();
|
||||
abstract InputSystem getInput();
|
||||
|
||||
|
||||
/**
|
||||
* @return display system
|
||||
*/
|
||||
abstract DisplaySystem disp();
|
||||
abstract DisplaySystem getDisplay();
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,30 +25,30 @@ public class AppAdapter implements AppAccess {
|
||||
|
||||
|
||||
@Override
|
||||
public final SoundSystem snd()
|
||||
public final SoundSystem getSoundSystem()
|
||||
{
|
||||
return app.snd();
|
||||
return app.getSoundSystem();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final InputSystem input()
|
||||
public final InputSystem getInput()
|
||||
{
|
||||
return app.input();
|
||||
return app.getInput();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final DisplaySystem disp()
|
||||
public final DisplaySystem getDisplay()
|
||||
{
|
||||
return app.disp();
|
||||
return app.getDisplay();
|
||||
}
|
||||
|
||||
|
||||
@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.control.bus.clients.RootBusNode;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
|
||||
@@ -25,23 +26,23 @@ public abstract class AppModule extends RootBusNode implements AppAccess {
|
||||
|
||||
|
||||
@Override
|
||||
public final SoundSystem snd()
|
||||
public final SoundSystem getSoundSystem()
|
||||
{
|
||||
return app.snd();
|
||||
return app.getSoundSystem();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final InputSystem input()
|
||||
public final InputSystem getInput()
|
||||
{
|
||||
return app.input();
|
||||
return app.getInput();
|
||||
}
|
||||
|
||||
|
||||
@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.control.bus.clients.BusNode;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
|
||||
@@ -25,23 +26,23 @@ public abstract class AppSubModule extends BusNode implements AppAccess {
|
||||
|
||||
|
||||
@Override
|
||||
public final SoundSystem snd()
|
||||
public final SoundSystem getSoundSystem()
|
||||
{
|
||||
return app.snd();
|
||||
return app.getSoundSystem();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final InputSystem input()
|
||||
public final InputSystem getInput()
|
||||
{
|
||||
return app.input();
|
||||
return app.getInput();
|
||||
}
|
||||
|
||||
|
||||
@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();
|
||||
|
||||
while (running) {
|
||||
disp().beginFrame();
|
||||
getDisplay().beginFrame();
|
||||
|
||||
bus().send(new UpdateEvent(timer.getDelta()));
|
||||
getEventBus().send(new UpdateEvent(timer.getDelta()));
|
||||
|
||||
Runnable r;
|
||||
while ((r = taskQueue.poll()) != null) {
|
||||
@@ -61,7 +61,7 @@ public abstract class GameLoop extends AppModule implements MainLoopTaskRequest.
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
+5
-6
@@ -1,13 +1,12 @@
|
||||
package mightypork.gamecore.control;
|
||||
package mightypork.gamecore.control.bus.clients;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mightypork.gamecore.control.bus.BusAccess;
|
||||
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.");
|
||||
}
|
||||
|
||||
if (bus().isClientValid(client)) {
|
||||
if (getEventBus().isClientValid(client)) {
|
||||
clients.add(client);
|
||||
}
|
||||
}
|
||||
@@ -104,9 +103,9 @@ public abstract class BusNode implements BusAccess, DelegatingClient, Toggleable
|
||||
|
||||
|
||||
@Override
|
||||
public final EventBus bus()
|
||||
public final EventBus getEventBus()
|
||||
{
|
||||
return busAccess.bus();
|
||||
return busAccess.getEventBus();
|
||||
}
|
||||
|
||||
}
|
||||
+4
-3
@@ -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;
|
||||
|
||||
|
||||
@@ -13,7 +14,7 @@ public abstract class RootBusNode extends BusNode implements Destroyable {
|
||||
public RootBusNode(BusAccess busAccess) {
|
||||
super(busAccess);
|
||||
|
||||
bus().subscribe(this);
|
||||
getEventBus().subscribe(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +23,7 @@ public abstract class RootBusNode extends BusNode implements Destroyable {
|
||||
{
|
||||
deinit();
|
||||
|
||||
bus().unsubscribe(this);
|
||||
getEventBus().unsubscribe(this);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -9,14 +9,14 @@ import org.lwjgl.input.Keyboard;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class KeyboardEvent implements Event<KeyboardEvent.Listener> {
|
||||
public class KeyEvent implements Event<KeyEvent.Listener> {
|
||||
|
||||
private final int key;
|
||||
private final boolean down;
|
||||
private final char c;
|
||||
|
||||
|
||||
public KeyboardEvent(int key, char c, boolean down) {
|
||||
public KeyEvent(int key, char c, boolean down) {
|
||||
this.key = key;
|
||||
this.c = c;
|
||||
this.down = down;
|
||||
@@ -72,7 +72,7 @@ public class KeyboardEvent implements Event<KeyboardEvent.Listener> {
|
||||
*
|
||||
* @param event event
|
||||
*/
|
||||
void receive(KeyboardEvent event);
|
||||
void receive(KeyEvent event);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import mightypork.gamecore.control.interf.Updateable;
|
||||
* @author MightyPork
|
||||
*/
|
||||
// sending via queue would hog the bus
|
||||
|
||||
@UnloggedEvent
|
||||
@ImmediateEvent
|
||||
public class UpdateEvent implements Event<Updateable> {
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package mightypork.gamecore.control.interf;
|
||||
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(value={ElementType.METHOD})
|
||||
public @interface NoImpl {
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ package mightypork.gamecore.gui.renderers;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.BusNode;
|
||||
import mightypork.gamecore.control.bus.EventBus;
|
||||
import mightypork.gamecore.control.bus.clients.BusNode;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ public abstract class LayeredScreen extends Screen {
|
||||
*/
|
||||
protected final void addLayer(ScreenLayer layer)
|
||||
{
|
||||
this.layers.add(layer); // will be rendered from last to first
|
||||
addChildClient(layer); // connect to bus
|
||||
this.layers.add(layer);
|
||||
addChildClient(layer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ package mightypork.gamecore.gui.screens;
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppSubModule;
|
||||
import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
||||
import mightypork.gamecore.control.interf.NoImpl;
|
||||
import mightypork.gamecore.gui.renderers.Renderable;
|
||||
import mightypork.gamecore.input.KeyBinder;
|
||||
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
|
||||
*/
|
||||
protected abstract void onScreenEnter();
|
||||
@NoImpl
|
||||
protected void onScreenEnter()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@NoImpl
|
||||
protected void onSizeChanged(Coord size)
|
||||
{
|
||||
// no impl
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +141,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -44,14 +44,14 @@ public abstract class ScreenLayer extends AppSubModule implements Renderable, Re
|
||||
}
|
||||
|
||||
|
||||
protected Screen screen()
|
||||
protected final Screen getScreen()
|
||||
{
|
||||
return screen;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
public final Rect getRect()
|
||||
{
|
||||
return screen.getRect();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.HashMap;
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppModule;
|
||||
import mightypork.gamecore.control.bus.events.ScreenRequestEvent;
|
||||
import mightypork.gamecore.control.interf.NoImpl;
|
||||
import mightypork.gamecore.gui.renderers.Renderable;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
@@ -52,9 +53,10 @@ public class ScreenRegistry extends AppModule implements ScreenRequestEvent.List
|
||||
|
||||
|
||||
@Override
|
||||
@NoImpl
|
||||
protected void deinit()
|
||||
{
|
||||
// no impl
|
||||
//
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package mightypork.gamecore.input;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.RootBusNode;
|
||||
import mightypork.gamecore.control.bus.events.KeyboardEvent;
|
||||
import mightypork.gamecore.control.bus.clients.RootBusNode;
|
||||
import mightypork.gamecore.control.bus.events.KeyEvent;
|
||||
import mightypork.gamecore.control.bus.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.bus.events.MouseMotionEvent;
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
@@ -92,14 +92,16 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
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()) {
|
||||
onKeyEvent();
|
||||
}
|
||||
|
||||
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) {
|
||||
bus().send(new MouseButtonEvent(pos, button, down, wheeld));
|
||||
getEventBus().send(new MouseButtonEvent(pos, button, down, wheeld));
|
||||
}
|
||||
|
||||
moveSum.add_ip(move);
|
||||
@@ -132,7 +134,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
final boolean down = Keyboard.getEventKeyState();
|
||||
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)
|
||||
{
|
||||
Mouse.setGrabbed(grab);
|
||||
}
|
||||
|
||||
/** Horizontal mouse position */
|
||||
public static final NumberConstraint mouseX = new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
@@ -169,6 +177,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
}
|
||||
};
|
||||
|
||||
/** Vertical mouse position */
|
||||
public static final NumberConstraint mouseY = new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
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
|
||||
*/
|
||||
public class KeyBinding implements KeyboardEvent.Listener {
|
||||
public class KeyBinding implements KeyEvent.Listener {
|
||||
|
||||
private final KeyStroke keystroke;
|
||||
private Runnable handler;
|
||||
@@ -50,7 +50,7 @@ public class KeyBinding implements KeyboardEvent.Listener {
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(KeyboardEvent event)
|
||||
public void receive(KeyEvent event)
|
||||
{
|
||||
// ignore unrelated events
|
||||
if (!keystroke.getKeys().contains(event.getKey())) return;
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import mightypork.gamecore.control.bus.events.KeyboardEvent;
|
||||
import mightypork.gamecore.control.bus.events.KeyEvent;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import mightypork.utils.logging.Log;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener {
|
||||
public class KeyBindingPool implements KeyBinder, KeyEvent.Listener {
|
||||
|
||||
private final Set<KeyBinding> bindings = new HashSet<KeyBinding>();
|
||||
|
||||
@@ -61,7 +61,7 @@ public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener {
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(KeyboardEvent event)
|
||||
public void receive(KeyEvent event)
|
||||
{
|
||||
for (final KeyBinding kb : bindings) {
|
||||
kb.receive(event);
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
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.ResourceLoadRequest;
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
@@ -34,7 +34,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
|
||||
public AsyncResourceLoader(BusAccess app) {
|
||||
super("Deferred loader");
|
||||
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));
|
||||
|
||||
app.bus().send(new MainLoopTaskRequest(new Runnable() {
|
||||
app.getEventBus().send(new MainLoopTaskRequest(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
|
||||
@@ -6,7 +6,7 @@ import static org.lwjgl.opengl.GL11.*;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
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.timing.FpsMeter;
|
||||
import mightypork.utils.logging.Log;
|
||||
@@ -89,7 +89,7 @@ public class DisplaySystem extends RootBusNode implements RectConstraint {
|
||||
Display.update();
|
||||
}
|
||||
|
||||
bus().send(new ScreenChangeEvent(true, Display.isFullscreen(), getSize()));
|
||||
getEventBus().send(new ScreenChangeEvent(true, Display.isFullscreen(), getSize()));
|
||||
|
||||
} catch (final Throwable t) {
|
||||
Log.e("Failed to toggle fullscreen mode.", t);
|
||||
@@ -174,7 +174,7 @@ public class DisplaySystem extends RootBusNode implements RectConstraint {
|
||||
{
|
||||
// handle resize
|
||||
if (Display.wasResized()) {
|
||||
bus().send(new ScreenChangeEvent(false, Display.isFullscreen(), getSize()));
|
||||
getEventBus().send(new ScreenChangeEvent(false, Display.isFullscreen(), getSize()));
|
||||
}
|
||||
|
||||
glLoadIdentity();
|
||||
|
||||
@@ -36,7 +36,7 @@ public class FontBank extends AppAdapter {
|
||||
*/
|
||||
public void loadFont(String key, DeferredFont font)
|
||||
{
|
||||
bus().send(new ResourceLoadRequest(font));
|
||||
getEventBus().send(new ResourceLoadRequest(font));
|
||||
|
||||
fonts.put(key, font);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class TextureBank extends AppAdapter {
|
||||
tx.setFilter(filter_min, filter_mag);
|
||||
tx.setWrap(wrap);
|
||||
|
||||
bus().send(new ResourceLoadRequest(tx));
|
||||
getEventBus().send(new ResourceLoadRequest(tx));
|
||||
|
||||
textures.put(key, tx);
|
||||
lastTx = tx;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class App implements AppAccess {
|
||||
// modules
|
||||
private InputSystem inputSystem;
|
||||
private DisplaySystem displaySystem;
|
||||
private static SoundSystem soundSystem;
|
||||
private SoundSystem soundSystem;
|
||||
private EventBus eventBus;
|
||||
private GameLoop mainLoop;
|
||||
private ScreenRegistry screens;
|
||||
@@ -108,9 +108,9 @@ public class App implements AppAccess {
|
||||
{
|
||||
Log.i("Shutting down subsystems...");
|
||||
|
||||
if (bus() != null) {
|
||||
bus().send(new DestroyEvent());
|
||||
bus().destroy();
|
||||
if (getEventBus() != null) {
|
||||
getEventBus().send(new DestroyEvent());
|
||||
getEventBus().destroy();
|
||||
}
|
||||
|
||||
Log.i("Terminating...");
|
||||
@@ -209,20 +209,20 @@ public class App implements AppAccess {
|
||||
Log.f3("Registering channels...");
|
||||
|
||||
// framework events
|
||||
bus().addChannel(DestroyEvent.class, Destroyable.class);
|
||||
bus().addChannel(UpdateEvent.class, Updateable.class);
|
||||
getEventBus().addChannel(DestroyEvent.class, Destroyable.class);
|
||||
getEventBus().addChannel(UpdateEvent.class, Updateable.class);
|
||||
|
||||
// input events
|
||||
bus().addChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class);
|
||||
bus().addChannel(KeyboardEvent.class, KeyboardEvent.Listener.class);
|
||||
bus().addChannel(MouseMotionEvent.class, MouseMotionEvent.Listener.class);
|
||||
bus().addChannel(MouseButtonEvent.class, MouseButtonEvent.Listener.class);
|
||||
getEventBus().addChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class);
|
||||
getEventBus().addChannel(KeyEvent.class, KeyEvent.Listener.class);
|
||||
getEventBus().addChannel(MouseMotionEvent.class, MouseMotionEvent.Listener.class);
|
||||
getEventBus().addChannel(MouseButtonEvent.class, MouseButtonEvent.Listener.class);
|
||||
|
||||
// control events
|
||||
bus().addChannel(ScreenRequestEvent.class, ScreenRequestEvent.Listener.class);
|
||||
bus().addChannel(ResourceLoadRequest.class, ResourceLoadRequest.Listener.class);
|
||||
bus().addChannel(ActionRequest.class, ActionRequest.Listener.class);
|
||||
bus().addChannel(MainLoopTaskRequest.class, MainLoopTaskRequest.Listener.class);
|
||||
getEventBus().addChannel(ScreenRequestEvent.class, ScreenRequestEvent.Listener.class);
|
||||
getEventBus().addChannel(ResourceLoadRequest.class, ResourceLoadRequest.Listener.class);
|
||||
getEventBus().addChannel(ActionRequest.class, ActionRequest.Listener.class);
|
||||
getEventBus().addChannel(MainLoopTaskRequest.class, MainLoopTaskRequest.Listener.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -231,32 +231,32 @@ public class App implements AppAccess {
|
||||
Log.f3("Setting up hot keys...");
|
||||
|
||||
// Go fullscreen
|
||||
input().bindKeyStroke(new KeyStroke(Keys.KEY_F11), new Runnable() {
|
||||
getInput().bindKeyStroke(new KeyStroke(Keys.KEY_F11), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
bus().send(new ActionRequest(RequestType.FULLSCREEN));
|
||||
getEventBus().send(new ActionRequest(RequestType.FULLSCREEN));
|
||||
}
|
||||
});
|
||||
|
||||
// Take screenshot
|
||||
input().bindKeyStroke(new KeyStroke(Keys.KEY_F2), new Runnable() {
|
||||
getInput().bindKeyStroke(new KeyStroke(Keys.KEY_F2), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
bus().send(new ActionRequest(RequestType.SCREENSHOT));
|
||||
getEventBus().send(new ActionRequest(RequestType.SCREENSHOT));
|
||||
}
|
||||
});
|
||||
|
||||
// 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
|
||||
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
|
||||
*/
|
||||
@Override
|
||||
public SoundSystem snd()
|
||||
public SoundSystem getSoundSystem()
|
||||
{
|
||||
return soundSystem;
|
||||
}
|
||||
@@ -333,7 +333,7 @@ public class App implements AppAccess {
|
||||
* @return input system of the running instance
|
||||
*/
|
||||
@Override
|
||||
public InputSystem input()
|
||||
public InputSystem getInput()
|
||||
{
|
||||
return inputSystem;
|
||||
}
|
||||
@@ -343,7 +343,7 @@ public class App implements AppAccess {
|
||||
* @return display system of the running instance
|
||||
*/
|
||||
@Override
|
||||
public DisplaySystem disp()
|
||||
public DisplaySystem getDisplay()
|
||||
{
|
||||
return displaySystem;
|
||||
}
|
||||
@@ -353,7 +353,7 @@ public class App implements AppAccess {
|
||||
* @return event bus
|
||||
*/
|
||||
@Override
|
||||
public EventBus bus()
|
||||
public EventBus getEventBus()
|
||||
{
|
||||
return eventBus;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class MainLoop extends GameLoop implements ActionRequest.Listener {
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
disp().switchFullscreen();
|
||||
getDisplay().switchFullscreen();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class LayerBouncyBoxes extends ScreenLayer {
|
||||
@Override
|
||||
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
|
||||
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
|
||||
public String getId()
|
||||
{
|
||||
|
||||
@@ -97,7 +97,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
public void render()
|
||||
{
|
||||
cat.render();
|
||||
text.render(disp().getFps()+" fps");
|
||||
text.render(getDisplay().getFps()+" fps");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ public class ScreenTestCat extends LayeredScreen {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
snd().fadeOutAllLoops();
|
||||
bus().sendDelayed(new ActionRequest(RequestType.SHUTDOWN), 3);
|
||||
getSoundSystem().fadeOutAllLoops();
|
||||
getEventBus().sendDelayed(new ActionRequest(RequestType.SHUTDOWN), 3);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -36,22 +36,16 @@ public class ScreenTestCat extends LayeredScreen {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
bus().send(new ScreenRequestEvent("test.bouncy"));
|
||||
getEventBus().send(new ScreenRequestEvent("test.bouncy"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void deinitScreen()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onScreenEnter()
|
||||
{
|
||||
snd().fadeOutAllLoops();
|
||||
getSoundSystem().fadeOutAllLoops();
|
||||
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
|
||||
protected void renderScreen()
|
||||
{
|
||||
@@ -53,16 +32,6 @@ public class ScreenTestFont extends Screen {
|
||||
final Coord origin = getRect().getCenter().sub(space.half());
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user