From 6d7ee87ae690083f1d2ba8c685cabc63fbc2f82b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Mon, 7 Apr 2014 09:31:07 +0200 Subject: [PATCH] Cleanup of annotations, fixed some bus logic. --- src/mightypork/rogue/App.java | 18 +----- src/mightypork/rogue/MainLoop.java | 29 +++++----- src/mightypork/rogue/Res.java | 4 +- .../rogue/bus/events/ActionRequest.java | 6 +- .../rogue/bus/events/KeyboardEvent.java | 2 - .../rogue/bus/events/MainLoopTaskRequest.java | 6 +- .../rogue/bus/events/MouseButtonEvent.java | 2 - .../rogue/bus/events/MouseMotionEvent.java | 2 - .../rogue/bus/events/ResourceLoadRequest.java | 6 +- .../rogue/bus/events/ScreenChangeEvent.java | 2 - .../rogue/bus/events/ScreenRequestEvent.java | 6 +- .../rogue/gui/constraints/ColumnHolder.java | 4 +- .../rogue/gui/constraints/ElementHolder.java | 10 ++-- ...hContext.java => PluggableRenderable.java} | 7 +-- .../rogue/gui/constraints/RowHolder.java | 4 +- .../gui/{ => screens}/LayeredScreen.java | 2 +- .../rogue/gui/{ => screens}/Screen.java | 2 +- .../rogue/gui/{ => screens}/ScreenLayer.java | 2 +- .../gui/{ => screens}/ScreenRegistry.java | 6 +- .../screens/test_bouncyboxes/BouncyBox.java | 4 +- .../test_bouncyboxes/LayerBouncyBoxes.java | 4 +- .../test_bouncyboxes/ScreenTestBouncy.java | 2 +- .../test_cat_sound/LayerFlyingCat.java | 4 +- .../screens/test_cat_sound/ScreenTestCat.java | 2 +- .../gui/screens/test_font/ScreenTestFont.java | 2 +- .../rogue/util/SlickLogRedirector.java | 58 +++++++++++++++++++ .../utils/control/bus/EventBus.java | 35 +++++------ .../utils/control/bus/EventChannel.java | 4 +- .../utils/control/bus/events/Event.java | 16 +++++ .../bus/events/types/DelayedEvent.java | 22 +++++++ ...SingularEvent.java => ImmediateEvent.java} | 5 +- .../bus/events/types/SingleReceiverEvent.java | 16 +++++ .../math/constraints/SettableContext.java | 2 +- 33 files changed, 190 insertions(+), 106 deletions(-) rename src/mightypork/rogue/gui/constraints/{RenderableWithContext.java => PluggableRenderable.java} (54%) rename src/mightypork/rogue/gui/{ => screens}/LayeredScreen.java (95%) rename src/mightypork/rogue/gui/{ => screens}/Screen.java (98%) rename src/mightypork/rogue/gui/{ => screens}/ScreenLayer.java (96%) rename src/mightypork/rogue/gui/{ => screens}/ScreenRegistry.java (88%) create mode 100644 src/mightypork/rogue/util/SlickLogRedirector.java create mode 100644 src/mightypork/utils/control/bus/events/types/DelayedEvent.java rename src/mightypork/utils/control/bus/events/types/{SingularEvent.java => ImmediateEvent.java} (55%) create mode 100644 src/mightypork/utils/control/bus/events/types/SingleReceiverEvent.java diff --git a/src/mightypork/rogue/App.java b/src/mightypork/rogue/App.java index b0bf5d0..ea18d9f 100644 --- a/src/mightypork/rogue/App.java +++ b/src/mightypork/rogue/App.java @@ -4,14 +4,13 @@ package mightypork.rogue; import java.io.File; import java.io.RandomAccessFile; import java.nio.channels.FileLock; -import java.util.ArrayList; import java.util.logging.Level; import javax.swing.JOptionPane; import mightypork.rogue.bus.events.*; import mightypork.rogue.bus.events.ActionRequest.RequestType; -import mightypork.rogue.gui.ScreenRegistry; +import mightypork.rogue.gui.screens.ScreenRegistry; import mightypork.rogue.gui.screens.test_bouncyboxes.ScreenTestBouncy; import mightypork.rogue.gui.screens.test_cat_sound.ScreenTestCat; import mightypork.rogue.gui.screens.test_font.ScreenTestFont; @@ -105,7 +104,7 @@ public class App implements AppAccess { { Log.i("Shutting down subsystems..."); - if(bus() != null) { + if (bus() != null) { bus().send(new DestroyEvent()); bus().destroy(); } @@ -181,18 +180,7 @@ public class App implements AppAccess { * Prepare main loop */ Log.f1("Preparing main loop..."); - final ArrayList loopTasks = new ArrayList(); - - loopTasks.add(new Runnable() { - - @Override - public void run() - { - screens.render(); - } - }); - - mainLoop = new MainLoop(this, loopTasks); + mainLoop = new MainLoop(this, screens); } diff --git a/src/mightypork/rogue/MainLoop.java b/src/mightypork/rogue/MainLoop.java index dcc2a50..4531987 100644 --- a/src/mightypork/rogue/MainLoop.java +++ b/src/mightypork/rogue/MainLoop.java @@ -1,16 +1,15 @@ package mightypork.rogue; -import java.util.ArrayList; -import java.util.List; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import mightypork.rogue.bus.Subsystem; import mightypork.rogue.bus.events.ActionRequest; -import mightypork.rogue.bus.events.UpdateEvent; import mightypork.rogue.bus.events.ActionRequest.RequestType; import mightypork.rogue.bus.events.MainLoopTaskRequest; +import mightypork.rogue.bus.events.UpdateEvent; +import mightypork.rogue.render.Renderable; import mightypork.rogue.tasks.TaskTakeScreenshot; import mightypork.rogue.util.Utils; import mightypork.utils.control.timing.TimerDelta; @@ -19,13 +18,17 @@ import mightypork.utils.control.timing.TimerDelta; public class MainLoop extends Subsystem implements ActionRequest.Listener, MainLoopTaskRequest.Listener { private final Queue taskQueue = new ConcurrentLinkedQueue(); - private final List regularTasks; + private final Renderable renderable; - public MainLoop(App app, ArrayList loopTasks) { + public MainLoop(App app, Renderable masterRenderable) { super(app); - this.regularTasks = loopTasks; + if (masterRenderable == null) { + throw new NullPointerException("Master renderable must not be null."); + } + + this.renderable = masterRenderable; } /** timer */ @@ -37,20 +40,18 @@ public class MainLoop extends Subsystem implements ActionRequest.Listener, MainL { timer = new TimerDelta(); - while (running) { - Runnable r; - while ((r = taskQueue.poll()) != null) { - r.run(); - } - + while (running) { disp().beginFrame(); bus().send(new UpdateEvent(timer.getDelta())); - for (final Runnable r2 : regularTasks) { - r2.run(); + Runnable r; + while ((r = taskQueue.poll()) != null) { + r.run(); } + renderable.render(); + disp().endFrame(); } } diff --git a/src/mightypork/rogue/Res.java b/src/mightypork/rogue/Res.java index 636e8d8..c86dc39 100644 --- a/src/mightypork/rogue/Res.java +++ b/src/mightypork/rogue/Res.java @@ -9,10 +9,10 @@ import mightypork.rogue.loading.AsyncResourceLoader; import mightypork.rogue.sound.SoundBank; import mightypork.rogue.sound.players.EffectPlayer; import mightypork.rogue.sound.players.LoopPlayer; -import mightypork.rogue.textures.TextureBank; -import mightypork.rogue.textures.TxQuad; import mightypork.rogue.textures.FilteredTexture.Filter; import mightypork.rogue.textures.FilteredTexture.Wrap; +import mightypork.rogue.textures.TextureBank; +import mightypork.rogue.textures.TxQuad; import org.newdawn.slick.opengl.Texture; diff --git a/src/mightypork/rogue/bus/events/ActionRequest.java b/src/mightypork/rogue/bus/events/ActionRequest.java index cb0cc9e..3dcd53c 100644 --- a/src/mightypork/rogue/bus/events/ActionRequest.java +++ b/src/mightypork/rogue/bus/events/ActionRequest.java @@ -2,8 +2,7 @@ package mightypork.rogue.bus.events; import mightypork.utils.control.bus.events.Event; -import mightypork.utils.control.bus.events.types.QueuedEvent; -import mightypork.utils.control.bus.events.types.SingularEvent; +import mightypork.utils.control.bus.events.types.SingleReceiverEvent; /** @@ -11,8 +10,7 @@ import mightypork.utils.control.bus.events.types.SingularEvent; * * @author MightyPork */ -@SingularEvent -@QueuedEvent +@SingleReceiverEvent public class ActionRequest implements Event { private final RequestType type; diff --git a/src/mightypork/rogue/bus/events/KeyboardEvent.java b/src/mightypork/rogue/bus/events/KeyboardEvent.java index beab14b..ab6c162 100644 --- a/src/mightypork/rogue/bus/events/KeyboardEvent.java +++ b/src/mightypork/rogue/bus/events/KeyboardEvent.java @@ -2,7 +2,6 @@ package mightypork.rogue.bus.events; import mightypork.utils.control.bus.events.Event; -import mightypork.utils.control.bus.events.types.QueuedEvent; import org.lwjgl.input.Keyboard; @@ -12,7 +11,6 @@ import org.lwjgl.input.Keyboard; * * @author MightyPork */ -@QueuedEvent public class KeyboardEvent implements Event { private final int key; diff --git a/src/mightypork/rogue/bus/events/MainLoopTaskRequest.java b/src/mightypork/rogue/bus/events/MainLoopTaskRequest.java index eeb688d..1014985 100644 --- a/src/mightypork/rogue/bus/events/MainLoopTaskRequest.java +++ b/src/mightypork/rogue/bus/events/MainLoopTaskRequest.java @@ -2,8 +2,7 @@ package mightypork.rogue.bus.events; import mightypork.utils.control.bus.events.Event; -import mightypork.utils.control.bus.events.types.QueuedEvent; -import mightypork.utils.control.bus.events.types.SingularEvent; +import mightypork.utils.control.bus.events.types.SingleReceiverEvent; /** @@ -11,8 +10,7 @@ import mightypork.utils.control.bus.events.types.SingularEvent; * * @author MightyPork */ -@SingularEvent -@QueuedEvent +@SingleReceiverEvent public class MainLoopTaskRequest implements Event { private final Runnable task; diff --git a/src/mightypork/rogue/bus/events/MouseButtonEvent.java b/src/mightypork/rogue/bus/events/MouseButtonEvent.java index 22cda95..bd498b7 100644 --- a/src/mightypork/rogue/bus/events/MouseButtonEvent.java +++ b/src/mightypork/rogue/bus/events/MouseButtonEvent.java @@ -2,7 +2,6 @@ package mightypork.rogue.bus.events; import mightypork.utils.control.bus.events.Event; -import mightypork.utils.control.bus.events.types.QueuedEvent; import mightypork.utils.math.coord.Coord; @@ -11,7 +10,6 @@ import mightypork.utils.math.coord.Coord; * * @author MightyPork */ -@QueuedEvent public class MouseButtonEvent implements Event { public static final int BUTTON_LEFT = 0; diff --git a/src/mightypork/rogue/bus/events/MouseMotionEvent.java b/src/mightypork/rogue/bus/events/MouseMotionEvent.java index 6c16f56..c43c2ce 100644 --- a/src/mightypork/rogue/bus/events/MouseMotionEvent.java +++ b/src/mightypork/rogue/bus/events/MouseMotionEvent.java @@ -2,7 +2,6 @@ package mightypork.rogue.bus.events; import mightypork.utils.control.bus.events.Event; -import mightypork.utils.control.bus.events.types.QueuedEvent; import mightypork.utils.math.coord.Coord; @@ -11,7 +10,6 @@ import mightypork.utils.math.coord.Coord; * * @author MightyPork */ -@QueuedEvent public class MouseMotionEvent implements Event { private final Coord move; diff --git a/src/mightypork/rogue/bus/events/ResourceLoadRequest.java b/src/mightypork/rogue/bus/events/ResourceLoadRequest.java index df7679c..5593ebc 100644 --- a/src/mightypork/rogue/bus/events/ResourceLoadRequest.java +++ b/src/mightypork/rogue/bus/events/ResourceLoadRequest.java @@ -3,8 +3,7 @@ package mightypork.rogue.bus.events; import mightypork.rogue.loading.DeferredResource; import mightypork.utils.control.bus.events.Event; -import mightypork.utils.control.bus.events.types.QueuedEvent; -import mightypork.utils.control.bus.events.types.SingularEvent; +import mightypork.utils.control.bus.events.types.SingleReceiverEvent; /** @@ -12,8 +11,7 @@ import mightypork.utils.control.bus.events.types.SingularEvent; * * @author MightyPork */ -@SingularEvent -@QueuedEvent +@SingleReceiverEvent public class ResourceLoadRequest implements Event { private final DeferredResource resource; diff --git a/src/mightypork/rogue/bus/events/ScreenChangeEvent.java b/src/mightypork/rogue/bus/events/ScreenChangeEvent.java index bca5dad..ce7c73a 100644 --- a/src/mightypork/rogue/bus/events/ScreenChangeEvent.java +++ b/src/mightypork/rogue/bus/events/ScreenChangeEvent.java @@ -2,7 +2,6 @@ package mightypork.rogue.bus.events; import mightypork.utils.control.bus.events.Event; -import mightypork.utils.control.bus.events.types.QueuedEvent; import mightypork.utils.math.coord.Coord; @@ -11,7 +10,6 @@ import mightypork.utils.math.coord.Coord; * * @author MightyPork */ -@QueuedEvent public class ScreenChangeEvent implements Event { private final boolean fullscreen; diff --git a/src/mightypork/rogue/bus/events/ScreenRequestEvent.java b/src/mightypork/rogue/bus/events/ScreenRequestEvent.java index aee0f65..8656f4b 100644 --- a/src/mightypork/rogue/bus/events/ScreenRequestEvent.java +++ b/src/mightypork/rogue/bus/events/ScreenRequestEvent.java @@ -2,8 +2,7 @@ package mightypork.rogue.bus.events; import mightypork.utils.control.bus.events.Event; -import mightypork.utils.control.bus.events.types.QueuedEvent; -import mightypork.utils.control.bus.events.types.SingularEvent; +import mightypork.utils.control.bus.events.types.SingleReceiverEvent; /** @@ -11,8 +10,7 @@ import mightypork.utils.control.bus.events.types.SingularEvent; * * @author MightyPork */ -@SingularEvent -@QueuedEvent +@SingleReceiverEvent public class ScreenRequestEvent implements Event { private final String scrName; diff --git a/src/mightypork/rogue/gui/constraints/ColumnHolder.java b/src/mightypork/rogue/gui/constraints/ColumnHolder.java index 3347bac..371b94d 100644 --- a/src/mightypork/rogue/gui/constraints/ColumnHolder.java +++ b/src/mightypork/rogue/gui/constraints/ColumnHolder.java @@ -29,7 +29,7 @@ public class ColumnHolder extends ElementHolder { * * @param elem */ - public void addRow(RenderableWithContext elem) + public void addRow(PluggableRenderable elem) { if (elem == null) return; add(elem, c_column(null, cols, col++)); @@ -37,7 +37,7 @@ public class ColumnHolder extends ElementHolder { @Override - public void remove(RenderableWithContext elem) + public void remove(PluggableRenderable elem) { throw new UnsupportedOperationException("Can't remove from ColumnHolder."); } diff --git a/src/mightypork/rogue/gui/constraints/ElementHolder.java b/src/mightypork/rogue/gui/constraints/ElementHolder.java index 05c9313..061f0fc 100644 --- a/src/mightypork/rogue/gui/constraints/ElementHolder.java +++ b/src/mightypork/rogue/gui/constraints/ElementHolder.java @@ -13,14 +13,14 @@ import mightypork.utils.math.coord.Rect; /** - * Bag for {@link RenderableWithContext} elements with constraints.
+ * Bag for {@link PluggableRenderable} elements with constraints.
* Elements are exposed to {@link EventBus}. * * @author MightyPork */ -public class ElementHolder extends ChildClient implements ConstraintContext, RenderableWithContext { +public class ElementHolder extends ChildClient implements ConstraintContext, PluggableRenderable { - private final LinkedList elements = new LinkedList(); + private final LinkedList elements = new LinkedList(); private ConstraintContext context; @@ -65,7 +65,7 @@ public class ElementHolder extends ChildClient implements ConstraintContext, Ren * @param constraint Constraint to be used for the element. It's context * will be set to this {@link ElementHolder} */ - public void add(RenderableWithContext elem, RectConstraint constraint) + public void add(PluggableRenderable elem, RectConstraint constraint) { if (elem == null) return; @@ -82,7 +82,7 @@ public class ElementHolder extends ChildClient implements ConstraintContext, Ren * * @param elem */ - public void remove(RenderableWithContext elem) + public void remove(PluggableRenderable elem) { if (elem == null) return; elements.remove(elem); diff --git a/src/mightypork/rogue/gui/constraints/RenderableWithContext.java b/src/mightypork/rogue/gui/constraints/PluggableRenderable.java similarity index 54% rename from src/mightypork/rogue/gui/constraints/RenderableWithContext.java rename to src/mightypork/rogue/gui/constraints/PluggableRenderable.java index 4ea971f..d2befc5 100644 --- a/src/mightypork/rogue/gui/constraints/RenderableWithContext.java +++ b/src/mightypork/rogue/gui/constraints/PluggableRenderable.java @@ -2,7 +2,6 @@ package mightypork.rogue.gui.constraints; import mightypork.rogue.render.Renderable; -import mightypork.utils.math.constraints.ConstraintContext; import mightypork.utils.math.constraints.SettableContext; @@ -11,8 +10,6 @@ import mightypork.utils.math.constraints.SettableContext; * * @author MightyPork */ -public interface RenderableWithContext extends Renderable, SettableContext { - - @Override - void setContext(ConstraintContext context); +public interface PluggableRenderable extends Renderable, SettableContext { + // methods from both interfaces } diff --git a/src/mightypork/rogue/gui/constraints/RowHolder.java b/src/mightypork/rogue/gui/constraints/RowHolder.java index fb92f68..3158e4f 100644 --- a/src/mightypork/rogue/gui/constraints/RowHolder.java +++ b/src/mightypork/rogue/gui/constraints/RowHolder.java @@ -29,7 +29,7 @@ public class RowHolder extends ElementHolder { * * @param elem */ - public void addRow(RenderableWithContext elem) + public void addRow(PluggableRenderable elem) { if (elem == null) return; add(elem, c_row(null, rows, row++)); @@ -37,7 +37,7 @@ public class RowHolder extends ElementHolder { @Override - public void remove(RenderableWithContext elem) + public void remove(PluggableRenderable elem) { throw new UnsupportedOperationException("Can't remove from RowHolder."); } diff --git a/src/mightypork/rogue/gui/LayeredScreen.java b/src/mightypork/rogue/gui/screens/LayeredScreen.java similarity index 95% rename from src/mightypork/rogue/gui/LayeredScreen.java rename to src/mightypork/rogue/gui/screens/LayeredScreen.java index 7d558c0..f99ed79 100644 --- a/src/mightypork/rogue/gui/LayeredScreen.java +++ b/src/mightypork/rogue/gui/screens/LayeredScreen.java @@ -1,4 +1,4 @@ -package mightypork.rogue.gui; +package mightypork.rogue.gui.screens; import java.util.Collection; diff --git a/src/mightypork/rogue/gui/Screen.java b/src/mightypork/rogue/gui/screens/Screen.java similarity index 98% rename from src/mightypork/rogue/gui/Screen.java rename to src/mightypork/rogue/gui/screens/Screen.java index 936e0e3..94b24e3 100644 --- a/src/mightypork/rogue/gui/Screen.java +++ b/src/mightypork/rogue/gui/screens/Screen.java @@ -1,4 +1,4 @@ -package mightypork.rogue.gui; +package mightypork.rogue.gui.screens; import static org.lwjgl.opengl.GL11.*; diff --git a/src/mightypork/rogue/gui/ScreenLayer.java b/src/mightypork/rogue/gui/screens/ScreenLayer.java similarity index 96% rename from src/mightypork/rogue/gui/ScreenLayer.java rename to src/mightypork/rogue/gui/screens/ScreenLayer.java index fb7afe3..680886c 100644 --- a/src/mightypork/rogue/gui/ScreenLayer.java +++ b/src/mightypork/rogue/gui/screens/ScreenLayer.java @@ -1,4 +1,4 @@ -package mightypork.rogue.gui; +package mightypork.rogue.gui.screens; import mightypork.rogue.bus.ChildClient; diff --git a/src/mightypork/rogue/gui/ScreenRegistry.java b/src/mightypork/rogue/gui/screens/ScreenRegistry.java similarity index 88% rename from src/mightypork/rogue/gui/ScreenRegistry.java rename to src/mightypork/rogue/gui/screens/ScreenRegistry.java index f30a85f..c803fa5 100644 --- a/src/mightypork/rogue/gui/ScreenRegistry.java +++ b/src/mightypork/rogue/gui/screens/ScreenRegistry.java @@ -1,4 +1,4 @@ -package mightypork.rogue.gui; +package mightypork.rogue.gui.screens; import java.util.HashMap; @@ -6,10 +6,11 @@ import java.util.HashMap; import mightypork.rogue.AppAccess; import mightypork.rogue.bus.Subsystem; import mightypork.rogue.bus.events.ScreenRequestEvent; +import mightypork.rogue.render.Renderable; import mightypork.utils.logging.Log; -public class ScreenRegistry extends Subsystem implements ScreenRequestEvent.Listener { +public class ScreenRegistry extends Subsystem implements ScreenRequestEvent.Listener, Renderable { private final HashMap screens = new HashMap(); private Screen active = null; @@ -43,6 +44,7 @@ public class ScreenRegistry extends Subsystem implements ScreenRequestEvent.List } + @Override public void render() { if (active != null) active.render(); diff --git a/src/mightypork/rogue/gui/screens/test_bouncyboxes/BouncyBox.java b/src/mightypork/rogue/gui/screens/test_bouncyboxes/BouncyBox.java index e50b941..6ea47b6 100644 --- a/src/mightypork/rogue/gui/screens/test_bouncyboxes/BouncyBox.java +++ b/src/mightypork/rogue/gui/screens/test_bouncyboxes/BouncyBox.java @@ -5,7 +5,7 @@ import static mightypork.utils.math.constraints.ConstraintFactory.*; import java.util.Random; -import mightypork.rogue.gui.constraints.RenderableWithContext; +import mightypork.rogue.gui.constraints.PluggableRenderable; import mightypork.rogue.render.Render; import mightypork.utils.control.interf.Updateable; import mightypork.utils.math.animation.AnimDouble; @@ -17,7 +17,7 @@ import mightypork.utils.math.constraints.RectConstraint; import mightypork.utils.math.coord.Rect; -public class BouncyBox implements RenderableWithContext, Updateable, ConstraintContext { +public class BouncyBox implements PluggableRenderable, Updateable, ConstraintContext { private final Random rand = new Random(); diff --git a/src/mightypork/rogue/gui/screens/test_bouncyboxes/LayerBouncyBoxes.java b/src/mightypork/rogue/gui/screens/test_bouncyboxes/LayerBouncyBoxes.java index 86f4b99..4f5308c 100644 --- a/src/mightypork/rogue/gui/screens/test_bouncyboxes/LayerBouncyBoxes.java +++ b/src/mightypork/rogue/gui/screens/test_bouncyboxes/LayerBouncyBoxes.java @@ -6,9 +6,9 @@ import static mightypork.utils.math.constraints.ConstraintFactory.*; import java.util.ArrayList; import java.util.List; -import mightypork.rogue.gui.Screen; -import mightypork.rogue.gui.ScreenLayer; import mightypork.rogue.gui.constraints.RowHolder; +import mightypork.rogue.gui.screens.Screen; +import mightypork.rogue.gui.screens.ScreenLayer; import mightypork.utils.math.constraints.RectConstraint; diff --git a/src/mightypork/rogue/gui/screens/test_bouncyboxes/ScreenTestBouncy.java b/src/mightypork/rogue/gui/screens/test_bouncyboxes/ScreenTestBouncy.java index a40a38e..29ed812 100644 --- a/src/mightypork/rogue/gui/screens/test_bouncyboxes/ScreenTestBouncy.java +++ b/src/mightypork/rogue/gui/screens/test_bouncyboxes/ScreenTestBouncy.java @@ -3,7 +3,7 @@ package mightypork.rogue.gui.screens.test_bouncyboxes; import mightypork.rogue.AppAccess; import mightypork.rogue.bus.events.ScreenRequestEvent; -import mightypork.rogue.gui.LayeredScreen; +import mightypork.rogue.gui.screens.LayeredScreen; import mightypork.rogue.input.KeyStroke; import org.lwjgl.input.Keyboard; diff --git a/src/mightypork/rogue/gui/screens/test_cat_sound/LayerFlyingCat.java b/src/mightypork/rogue/gui/screens/test_cat_sound/LayerFlyingCat.java index a30e677..9c99cf6 100644 --- a/src/mightypork/rogue/gui/screens/test_cat_sound/LayerFlyingCat.java +++ b/src/mightypork/rogue/gui/screens/test_cat_sound/LayerFlyingCat.java @@ -7,8 +7,8 @@ import java.util.Random; import mightypork.rogue.Res; import mightypork.rogue.bus.events.MouseButtonEvent; -import mightypork.rogue.gui.Screen; -import mightypork.rogue.gui.ScreenLayer; +import mightypork.rogue.gui.screens.Screen; +import mightypork.rogue.gui.screens.ScreenLayer; import mightypork.rogue.input.KeyStroke; import mightypork.rogue.render.Render; import mightypork.utils.control.interf.Updateable; diff --git a/src/mightypork/rogue/gui/screens/test_cat_sound/ScreenTestCat.java b/src/mightypork/rogue/gui/screens/test_cat_sound/ScreenTestCat.java index 2cf9a7a..f1cb226 100644 --- a/src/mightypork/rogue/gui/screens/test_cat_sound/ScreenTestCat.java +++ b/src/mightypork/rogue/gui/screens/test_cat_sound/ScreenTestCat.java @@ -6,7 +6,7 @@ import mightypork.rogue.Res; import mightypork.rogue.bus.events.ActionRequest; import mightypork.rogue.bus.events.ActionRequest.RequestType; import mightypork.rogue.bus.events.ScreenRequestEvent; -import mightypork.rogue.gui.LayeredScreen; +import mightypork.rogue.gui.screens.LayeredScreen; import mightypork.rogue.input.KeyStroke; import org.lwjgl.input.Keyboard; diff --git a/src/mightypork/rogue/gui/screens/test_font/ScreenTestFont.java b/src/mightypork/rogue/gui/screens/test_font/ScreenTestFont.java index 2a8c192..1a81091 100644 --- a/src/mightypork/rogue/gui/screens/test_font/ScreenTestFont.java +++ b/src/mightypork/rogue/gui/screens/test_font/ScreenTestFont.java @@ -4,7 +4,7 @@ package mightypork.rogue.gui.screens.test_font; import mightypork.rogue.AppAccess; import mightypork.rogue.Res; import mightypork.rogue.fonts.GLFont; -import mightypork.rogue.gui.Screen; +import mightypork.rogue.gui.screens.Screen; import mightypork.rogue.render.Render; import mightypork.utils.math.coord.Coord; diff --git a/src/mightypork/rogue/util/SlickLogRedirector.java b/src/mightypork/rogue/util/SlickLogRedirector.java new file mode 100644 index 0000000..38838c5 --- /dev/null +++ b/src/mightypork/rogue/util/SlickLogRedirector.java @@ -0,0 +1,58 @@ +package mightypork.rogue.util; + +import mightypork.utils.logging.LogInstance; + +import org.newdawn.slick.util.LogSystem; + + +public class SlickLogRedirector implements LogSystem { + LogInstance l; + + public SlickLogRedirector(LogInstance log) { + this.l = log; + } + + @Override + public void error(String msg, Throwable e) + { + l.e(msg, e); + } + + @Override + public void error(Throwable e) + { + l.e(e); + } + + @Override + public void error(String msg) + { + l.e(msg); + } + + @Override + public void warn(String msg) + { + l.w(msg); + } + + @Override + public void warn(String msg, Throwable e) + { + l.e(msg, e); + } + + @Override + public void info(String msg) + { + l.i(msg); + } + + @Override + public void debug(String msg) + { + l.f3(msg); + } + + +} diff --git a/src/mightypork/utils/control/bus/EventBus.java b/src/mightypork/utils/control/bus/EventBus.java index 5aff720..10692ca 100644 --- a/src/mightypork/utils/control/bus/EventBus.java +++ b/src/mightypork/utils/control/bus/EventBus.java @@ -6,9 +6,9 @@ import java.util.concurrent.Delayed; import java.util.concurrent.TimeUnit; import mightypork.utils.control.bus.events.Event; +import mightypork.utils.control.bus.events.types.DelayedEvent; import mightypork.utils.control.bus.events.types.ImmediateEvent; -import mightypork.utils.control.bus.events.types.QueuedEvent; -import mightypork.utils.control.bus.events.types.SingularEvent; +import mightypork.utils.control.bus.events.types.SingleReceiverEvent; import mightypork.utils.control.interf.Destroyable; import mightypork.utils.logging.Log; @@ -27,11 +27,11 @@ final public class EventBus implements Destroyable { private final BufferedHashSet clients = new BufferedHashSet(); /** Messages queued for delivery */ - private final DelayQueue sendQueue = new DelayQueue(); + private final DelayQueue sendQueue = new DelayQueue(); /** Queue polling thread */ private final QueuePollingThread busThread; - + /** Whether the bus was destroyed */ private boolean dead = false; @@ -110,17 +110,18 @@ final public class EventBus implements Destroyable { { assertLive(); - if(event.getClass().isAnnotationPresent(QueuedEvent.class)) { - sendQueued(event); + DelayedEvent adelay = event.getClass().getAnnotation(DelayedEvent.class); + if (adelay != null) { + sendDelayed(event, adelay.delay()); return; } - if(event.getClass().isAnnotationPresent(ImmediateEvent.class)) { + if (event.getClass().isAnnotationPresent(ImmediateEvent.class)) { sendDirect(event); return; } - dispatch(event); + sendQueued(event); } @@ -147,9 +148,9 @@ final public class EventBus implements Destroyable { { assertLive(); - final DelayedEvent dm = new DelayedEvent(delay, event); + final DelayQueueEntry dm = new DelayQueueEntry(delay, event); - if(logSending) Log.f3(" Q "+Log.str(event)+", t = +"+delay+"s"); + if (logSending) Log.f3(" Q " + Log.str(event) + ", t = +" + delay + "s"); sendQueue.add(dm); } @@ -166,7 +167,7 @@ final public class EventBus implements Destroyable { { assertLive(); - if(logSending) Log.f3(" D "+Log.str(event)); + if (logSending) Log.f3(" D " + Log.str(event)); dispatch(event); } @@ -190,7 +191,7 @@ final public class EventBus implements Destroyable { boolean sent = false; boolean accepted = false; - final boolean singular = event.getClass().isAnnotationPresent(SingularEvent.class); + final boolean singular = event.getClass().isAnnotationPresent(SingleReceiverEvent.class); for (final EventChannel b : channels) { if (b.canBroadcast(event)) { @@ -201,7 +202,7 @@ final public class EventBus implements Destroyable { if (sent && singular) break; } - if(!accepted) Log.e(" Not accepted by any channel: " + Log.str(event)); + if (!accepted) Log.e(" Not accepted by any channel: " + Log.str(event)); channels.setBuffering(false); clients.setBuffering(false); @@ -234,7 +235,7 @@ final public class EventBus implements Destroyable { { assertLive(); - clients.remove(client); + clients.remove(client); } @@ -253,13 +254,13 @@ final public class EventBus implements Destroyable { return false; } - private class DelayedEvent implements Delayed { + private class DelayQueueEntry implements Delayed { private final long due; private Event evt = null; - public DelayedEvent(double seconds, Event event) { + public DelayQueueEntry(double seconds, Event event) { super(); this.due = System.currentTimeMillis() + (long) (seconds * 1000); this.evt = event; @@ -300,7 +301,7 @@ final public class EventBus implements Destroyable { @Override public void run() { - DelayedEvent evt; + DelayQueueEntry evt; while (!stopped) { evt = null; diff --git a/src/mightypork/utils/control/bus/EventChannel.java b/src/mightypork/utils/control/bus/EventChannel.java index 450a2bf..987ab95 100644 --- a/src/mightypork/utils/control/bus/EventChannel.java +++ b/src/mightypork/utils/control/bus/EventChannel.java @@ -7,7 +7,7 @@ import java.util.HashSet; import mightypork.utils.control.bus.clients.DelegatingClient; import mightypork.utils.control.bus.clients.ToggleableClient; import mightypork.utils.control.bus.events.Event; -import mightypork.utils.control.bus.events.types.SingularEvent; +import mightypork.utils.control.bus.events.types.SingleReceiverEvent; import mightypork.utils.logging.Log; @@ -68,7 +68,7 @@ final public class EventChannel, CLIENT> { private boolean doBroadcast(final EVENT event, final Collection clients, final Collection processed) { boolean sent = false; - final boolean singular = event.getClass().isAnnotationPresent(SingularEvent.class); + final boolean singular = event.getClass().isAnnotationPresent(SingleReceiverEvent.class); for (final Object client : clients) { diff --git a/src/mightypork/utils/control/bus/events/Event.java b/src/mightypork/utils/control/bus/events/Event.java index 66e67f7..8f2bec6 100644 --- a/src/mightypork/utils/control/bus/events/Event.java +++ b/src/mightypork/utils/control/bus/events/Event.java @@ -1,8 +1,24 @@ package mightypork.utils.control.bus.events; +import mightypork.utils.control.bus.events.types.DelayedEvent; +import mightypork.utils.control.bus.events.types.ImmediateEvent; +import mightypork.utils.control.bus.events.types.SingleReceiverEvent; + + /** + *

* Something that can be handled by HANDLER. + *

+ *

+ * Can be annotated as {@link SingleReceiverEvent} to be delivered once only, + * and {@link DelayedEvent} or {@link ImmediateEvent} to specify default sending + * mode. + *

+ *

+ * Default sending mode (if not changed by annotations) is queued with + * zero delay. + *

* * @author MightyPork * @param handler type diff --git a/src/mightypork/utils/control/bus/events/types/DelayedEvent.java b/src/mightypork/utils/control/bus/events/types/DelayedEvent.java new file mode 100644 index 0000000..a5b7f21 --- /dev/null +++ b/src/mightypork/utils/control/bus/events/types/DelayedEvent.java @@ -0,0 +1,22 @@ +package mightypork.utils.control.bus.events.types; + + +import java.lang.annotation.*; + + +/** + * Event that should be queued with given delay (default: 0); + * + * @author MightyPork + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +@Documented +public @interface DelayedEvent { + + /** + * @return event dispatch delay [seconds] + */ + double delay() default 0; +} diff --git a/src/mightypork/utils/control/bus/events/types/SingularEvent.java b/src/mightypork/utils/control/bus/events/types/ImmediateEvent.java similarity index 55% rename from src/mightypork/utils/control/bus/events/types/SingularEvent.java rename to src/mightypork/utils/control/bus/events/types/ImmediateEvent.java index c41a97b..41f0f84 100644 --- a/src/mightypork/utils/control/bus/events/types/SingularEvent.java +++ b/src/mightypork/utils/control/bus/events/types/ImmediateEvent.java @@ -5,8 +5,7 @@ import java.lang.annotation.*; /** - * Event that is handled by only single client, and then discarded (ie. only one - * client receives it when it's broadcasted). + * Event that should not be queued. * * @author MightyPork */ @@ -14,4 +13,4 @@ import java.lang.annotation.*; @Target(ElementType.TYPE) @Inherited @Documented -public @interface SingularEvent {} +public @interface ImmediateEvent {} diff --git a/src/mightypork/utils/control/bus/events/types/SingleReceiverEvent.java b/src/mightypork/utils/control/bus/events/types/SingleReceiverEvent.java new file mode 100644 index 0000000..44a5d66 --- /dev/null +++ b/src/mightypork/utils/control/bus/events/types/SingleReceiverEvent.java @@ -0,0 +1,16 @@ +package mightypork.utils.control.bus.events.types; + + +import java.lang.annotation.*; + + +/** + * Handled only by the first client, then discarded. + * + * @author MightyPork + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +@Documented +public @interface SingleReceiverEvent {} diff --git a/src/mightypork/utils/math/constraints/SettableContext.java b/src/mightypork/utils/math/constraints/SettableContext.java index a1ff0cf..23be703 100644 --- a/src/mightypork/utils/math/constraints/SettableContext.java +++ b/src/mightypork/utils/math/constraints/SettableContext.java @@ -13,5 +13,5 @@ public interface SettableContext { * * @param context context */ - public void setContext(ConstraintContext context); + void setContext(ConstraintContext context); }