From d67b382f436c8ff493e3a1365cf0d214ad4d3188 Mon Sep 17 00:00:00 2001 From: ondra Date: Wed, 23 Apr 2014 20:22:34 +0200 Subject: [PATCH] weirdly broken world renderer while triny to optimize --- .../gamecore/audio/SoundSystem.java | 2 +- src/mightypork/gamecore/control/BaseApp.java | 2 +- src/mightypork/gamecore/control/GameLoop.java | 6 +- .../control/events/LayoutChangeEvent.java | 32 ----- .../control/events/MainLoopTaskRequest.java | 48 ------- .../control/events/ResourceLoadRequest.java | 49 ------- .../control/events/ScreenRequestEvent.java | 47 ------- .../events/{ => core}/DestroyEvent.java | 8 +- .../events/{ => core}/UpdateEvent.java | 11 +- .../control/events/gui/LayoutChangeEvent.java | 28 ++++ .../events/gui/LayoutChangeListener.java | 6 + .../events/{ => gui}/ViewportChangeEvent.java | 28 +--- .../events/gui/ViewportChangeListener.java | 16 +++ .../control/events/{ => input}/KeyEvent.java | 27 +--- .../control/events/input/KeyListener.java | 16 +++ .../events/{ => input}/MouseButtonEvent.java | 26 +--- .../events/input/MouseButtonListener.java | 16 +++ .../events/{ => input}/MouseMotionEvent.java | 26 +--- .../events/input/MouseMotionListener.java | 16 +++ .../events/requests/MainLoopRequest.java | 32 +++++ .../requests/MainLoopRequestListener.java | 16 +++ .../events/requests/ResourceLoadRequest.java | 33 +++++ .../requests/ResourceLoadRequestListener.java | 18 +++ .../events/requests/ScreenRequestEvent.java | 33 +++++ .../requests/ScreenRequestListener.java | 14 ++ .../gui/components/ClickableComponent.java | 6 +- .../gui/components/VisualComponent.java | 5 +- .../gamecore/gui/screens/BaseScreen.java | 5 +- .../gamecore/gui/screens/LayeredScreen.java | 56 ++++++-- .../gamecore/gui/screens/Overlay.java | 35 +++-- .../gamecore/gui/screens/ScreenRegistry.java | 9 +- .../gamecore/input/InputSystem.java | 6 +- src/mightypork/gamecore/input/KeyBinding.java | 5 +- .../gamecore/input/KeyBindingPool.java | 5 +- .../gamecore/loading/AsyncResourceLoader.java | 8 +- .../gamecore/render/DisplaySystem.java | 2 +- .../gamecore/render/fonts/FontBank.java | 2 +- .../gamecore/render/textures/TextureBank.java | 2 +- src/mightypork/rogue/App.java | 4 +- .../rogue/events/ActionRequest.java | 4 +- .../rogue/screens/CrossfadeOverlay.java | 4 +- .../rogue/screens/CrossfadeRequest.java | 4 +- src/mightypork/rogue/screens/FpsOverlay.java | 2 +- .../{GameGui.java => HudLayer.java} | 8 +- .../rogue/screens/gamescreen/ScreenGame.java | 50 ++++++- .../screens/gamescreen/WRBasicControls.java | 115 ---------------- .../rogue/screens/gamescreen/WorldLayer.java | 57 ++------ .../gamescreen/WorldRenderComponent.java | 44 ------- .../gamescreen/{ => gui}/HeartBar.java | 2 +- .../gamescreen/{ => gui}/NavItemSlot.java | 7 +- .../screens/gamescreen/world/MIPKeyWalk.java | 45 +++++++ .../gamescreen/world/MIPMouseWalk.java | 59 +++++++++ .../world/MapInteractionPlugin.java | 18 +++ .../screens/gamescreen/world/MapView.java | 124 ++++++++++++++++++ .../rogue/screens/main_menu/MenuLayer.java | 2 +- .../test_bouncyboxes/LayerBouncyBoxes.java | 2 +- .../screens/test_cat_sound/LayerColor.java | 2 +- .../test_cat_sound/LayerFlyingCat.java | 7 +- .../test_render/LayerTestGradient.java | 2 +- src/mightypork/rogue/world/PlayerControl.java | 42 +++--- src/mightypork/rogue/world/World.java | 18 +-- src/mightypork/rogue/world/WorldRenderer.java | 48 ++++--- .../world/level/render/MapRenderContext.java | 22 +++- .../util/constraints/DigestCache.java | 2 +- .../util/control/eventbus/BusEvent.java | 115 ++++++++++++++++ .../util/control/eventbus/EventBus.java | 54 ++++---- .../util/control/eventbus/EventChannel.java | 42 +++--- .../control/eventbus/clients/BusNode.java | 16 +-- .../util/control/eventbus/events/Event.java | 36 ----- .../events/flags/NonConsumableEvent.java | 20 +++ 70 files changed, 979 insertions(+), 700 deletions(-) delete mode 100644 src/mightypork/gamecore/control/events/LayoutChangeEvent.java delete mode 100644 src/mightypork/gamecore/control/events/MainLoopTaskRequest.java delete mode 100644 src/mightypork/gamecore/control/events/ResourceLoadRequest.java delete mode 100644 src/mightypork/gamecore/control/events/ScreenRequestEvent.java rename src/mightypork/gamecore/control/events/{ => core}/DestroyEvent.java (56%) rename src/mightypork/gamecore/control/events/{ => core}/UpdateEvent.java (64%) create mode 100644 src/mightypork/gamecore/control/events/gui/LayoutChangeEvent.java create mode 100644 src/mightypork/gamecore/control/events/gui/LayoutChangeListener.java rename src/mightypork/gamecore/control/events/{ => gui}/ViewportChangeEvent.java (67%) create mode 100644 src/mightypork/gamecore/control/events/gui/ViewportChangeListener.java rename src/mightypork/gamecore/control/events/{ => input}/KeyEvent.java (68%) create mode 100644 src/mightypork/gamecore/control/events/input/KeyListener.java rename src/mightypork/gamecore/control/events/{ => input}/MouseButtonEvent.java (81%) create mode 100644 src/mightypork/gamecore/control/events/input/MouseButtonListener.java rename src/mightypork/gamecore/control/events/{ => input}/MouseMotionEvent.java (58%) create mode 100644 src/mightypork/gamecore/control/events/input/MouseMotionListener.java create mode 100644 src/mightypork/gamecore/control/events/requests/MainLoopRequest.java create mode 100644 src/mightypork/gamecore/control/events/requests/MainLoopRequestListener.java create mode 100644 src/mightypork/gamecore/control/events/requests/ResourceLoadRequest.java create mode 100644 src/mightypork/gamecore/control/events/requests/ResourceLoadRequestListener.java create mode 100644 src/mightypork/gamecore/control/events/requests/ScreenRequestEvent.java create mode 100644 src/mightypork/gamecore/control/events/requests/ScreenRequestListener.java rename src/mightypork/rogue/screens/gamescreen/{GameGui.java => HudLayer.java} (89%) delete mode 100644 src/mightypork/rogue/screens/gamescreen/WRBasicControls.java delete mode 100644 src/mightypork/rogue/screens/gamescreen/WorldRenderComponent.java rename src/mightypork/rogue/screens/gamescreen/{ => gui}/HeartBar.java (96%) rename src/mightypork/rogue/screens/gamescreen/{ => gui}/NavItemSlot.java (89%) create mode 100644 src/mightypork/rogue/screens/gamescreen/world/MIPKeyWalk.java create mode 100644 src/mightypork/rogue/screens/gamescreen/world/MIPMouseWalk.java create mode 100644 src/mightypork/rogue/screens/gamescreen/world/MapInteractionPlugin.java create mode 100644 src/mightypork/rogue/screens/gamescreen/world/MapView.java create mode 100644 src/mightypork/util/control/eventbus/BusEvent.java delete mode 100644 src/mightypork/util/control/eventbus/events/Event.java create mode 100644 src/mightypork/util/control/eventbus/events/flags/NonConsumableEvent.java diff --git a/src/mightypork/gamecore/audio/SoundSystem.java b/src/mightypork/gamecore/audio/SoundSystem.java index 149280d..f9d0318 100644 --- a/src/mightypork/gamecore/audio/SoundSystem.java +++ b/src/mightypork/gamecore/audio/SoundSystem.java @@ -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.events.ResourceLoadRequest; +import mightypork.gamecore.control.events.requests.ResourceLoadRequest; import mightypork.util.constraints.vect.Vect; import mightypork.util.constraints.vect.mutable.VectVar; import mightypork.util.control.eventbus.clients.RootBusNode; diff --git a/src/mightypork/gamecore/control/BaseApp.java b/src/mightypork/gamecore/control/BaseApp.java index a23b829..0f51d00 100644 --- a/src/mightypork/gamecore/control/BaseApp.java +++ b/src/mightypork/gamecore/control/BaseApp.java @@ -8,7 +8,7 @@ import java.util.logging.Level; import javax.swing.JOptionPane; import mightypork.gamecore.audio.SoundSystem; -import mightypork.gamecore.control.events.DestroyEvent; +import mightypork.gamecore.control.events.core.DestroyEvent; import mightypork.gamecore.gui.screens.ScreenRegistry; import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.render.DisplaySystem; diff --git a/src/mightypork/gamecore/control/GameLoop.java b/src/mightypork/gamecore/control/GameLoop.java index e4ceb35..3cc42c3 100644 --- a/src/mightypork/gamecore/control/GameLoop.java +++ b/src/mightypork/gamecore/control/GameLoop.java @@ -4,8 +4,8 @@ package mightypork.gamecore.control; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; -import mightypork.gamecore.control.events.MainLoopTaskRequest; -import mightypork.gamecore.control.events.UpdateEvent; +import mightypork.gamecore.control.events.core.UpdateEvent; +import mightypork.gamecore.control.events.requests.MainLoopRequestListener; import mightypork.gamecore.gui.screens.ScreenRegistry; import mightypork.gamecore.render.Renderable; import mightypork.util.annotations.DefaultImpl; @@ -17,7 +17,7 @@ import mightypork.util.control.timing.TimerDelta; * * @author MightyPork */ -public abstract class GameLoop extends AppModule implements MainLoopTaskRequest.Listener { +public abstract class GameLoop extends AppModule implements MainLoopRequestListener { private final Queue taskQueue = new ConcurrentLinkedQueue<>(); private TimerDelta timer; diff --git a/src/mightypork/gamecore/control/events/LayoutChangeEvent.java b/src/mightypork/gamecore/control/events/LayoutChangeEvent.java deleted file mode 100644 index f5c0e17..0000000 --- a/src/mightypork/gamecore/control/events/LayoutChangeEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -package mightypork.gamecore.control.events; - - -import mightypork.util.control.eventbus.events.Event; -import mightypork.util.control.eventbus.events.flags.ImmediateEvent; - - -/** - * Intended use is to notify UI component sub-clients that they should poll - * their cached constraints. - * - * @author MightyPork - */ -@ImmediateEvent -public class LayoutChangeEvent implements Event { - - public LayoutChangeEvent() - { - } - - - @Override - public void handleBy(Listener handler) - { - handler.onLayoutChanged(); - } - - public interface Listener { - - public void onLayoutChanged(); - } -} diff --git a/src/mightypork/gamecore/control/events/MainLoopTaskRequest.java b/src/mightypork/gamecore/control/events/MainLoopTaskRequest.java deleted file mode 100644 index 60b860e..0000000 --- a/src/mightypork/gamecore/control/events/MainLoopTaskRequest.java +++ /dev/null @@ -1,48 +0,0 @@ -package mightypork.gamecore.control.events; - - -import mightypork.util.control.eventbus.events.Event; -import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent; - - -/** - * Request to execute given {@link Runnable} in main loop. - * - * @author MightyPork - */ -@SingleReceiverEvent -public class MainLoopTaskRequest implements Event { - - private final Runnable task; - - - /** - * @param task task to run on main thread in rendering context - */ - public MainLoopTaskRequest(Runnable task) - { - this.task = task; - } - - - @Override - public void handleBy(Listener handler) - { - handler.queueTask(task); - } - - /** - * {@link MainLoopTaskRequest} listener - * - * @author MightyPork - */ - public interface Listener { - - /** - * Perform the requested action - * - * @param request - */ - void queueTask(Runnable request); - } -} diff --git a/src/mightypork/gamecore/control/events/ResourceLoadRequest.java b/src/mightypork/gamecore/control/events/ResourceLoadRequest.java deleted file mode 100644 index d3045d1..0000000 --- a/src/mightypork/gamecore/control/events/ResourceLoadRequest.java +++ /dev/null @@ -1,49 +0,0 @@ -package mightypork.gamecore.control.events; - - -import mightypork.gamecore.loading.Deferred; -import mightypork.util.control.eventbus.events.Event; -import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent; - - -/** - * Request to load a deferred resource. - * - * @author MightyPork - */ -@SingleReceiverEvent -public class ResourceLoadRequest implements Event { - - private final Deferred resource; - - - /** - * @param resource resource to load - */ - public ResourceLoadRequest(Deferred resource) - { - this.resource = resource; - } - - - @Override - public void handleBy(Listener handler) - { - handler.loadResource(resource); - } - - /** - * {@link ResourceLoadRequest} listener - * - * @author MightyPork - */ - public interface Listener { - - /** - * Load a resource - * - * @param resource - */ - void loadResource(Deferred resource); - } -} diff --git a/src/mightypork/gamecore/control/events/ScreenRequestEvent.java b/src/mightypork/gamecore/control/events/ScreenRequestEvent.java deleted file mode 100644 index 62f0376..0000000 --- a/src/mightypork/gamecore/control/events/ScreenRequestEvent.java +++ /dev/null @@ -1,47 +0,0 @@ -package mightypork.gamecore.control.events; - - -import mightypork.util.control.eventbus.events.Event; -import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent; - - -/** - * Request to change screen - * - * @author MightyPork - */ -@SingleReceiverEvent -public class ScreenRequestEvent implements Event { - - private final String scrName; - - - /** - * @param screenKey screen name - */ - public ScreenRequestEvent(String screenKey) - { - scrName = screenKey; - } - - - @Override - public void handleBy(Listener handler) - { - handler.showScreen(scrName); - } - - /** - * {@link ScreenRequestEvent} listener - * - * @author MightyPork - */ - public interface Listener { - - /** - * @param key screen to show - */ - void showScreen(String key); - } - -} diff --git a/src/mightypork/gamecore/control/events/DestroyEvent.java b/src/mightypork/gamecore/control/events/core/DestroyEvent.java similarity index 56% rename from src/mightypork/gamecore/control/events/DestroyEvent.java rename to src/mightypork/gamecore/control/events/core/DestroyEvent.java index 3de1046..ae6afa1 100644 --- a/src/mightypork/gamecore/control/events/DestroyEvent.java +++ b/src/mightypork/gamecore/control/events/core/DestroyEvent.java @@ -1,9 +1,10 @@ -package mightypork.gamecore.control.events; +package mightypork.gamecore.control.events.core; import mightypork.util.control.Destroyable; -import mightypork.util.control.eventbus.events.Event; +import mightypork.util.control.eventbus.BusEvent; import mightypork.util.control.eventbus.events.flags.ImmediateEvent; +import mightypork.util.control.eventbus.events.flags.NonConsumableEvent; /** @@ -12,7 +13,8 @@ import mightypork.util.control.eventbus.events.flags.ImmediateEvent; * @author MightyPork */ @ImmediateEvent -public class DestroyEvent implements Event { +@NonConsumableEvent +public class DestroyEvent extends BusEvent { @Override public void handleBy(Destroyable handler) diff --git a/src/mightypork/gamecore/control/events/UpdateEvent.java b/src/mightypork/gamecore/control/events/core/UpdateEvent.java similarity index 64% rename from src/mightypork/gamecore/control/events/UpdateEvent.java rename to src/mightypork/gamecore/control/events/core/UpdateEvent.java index 0f9dd0a..1cf5b11 100644 --- a/src/mightypork/gamecore/control/events/UpdateEvent.java +++ b/src/mightypork/gamecore/control/events/core/UpdateEvent.java @@ -1,8 +1,9 @@ -package mightypork.gamecore.control.events; +package mightypork.gamecore.control.events.core; -import mightypork.util.control.eventbus.events.Event; +import mightypork.util.control.eventbus.BusEvent; import mightypork.util.control.eventbus.events.flags.ImmediateEvent; +import mightypork.util.control.eventbus.events.flags.NonConsumableEvent; import mightypork.util.control.eventbus.events.flags.UnloggedEvent; import mightypork.util.control.timing.Updateable; @@ -14,7 +15,8 @@ import mightypork.util.control.timing.Updateable; */ @UnloggedEvent @ImmediateEvent -public class UpdateEvent implements Event { +@NonConsumableEvent +public class UpdateEvent extends BusEvent { private final double deltaTime; @@ -22,8 +24,7 @@ public class UpdateEvent implements Event { /** * @param deltaTime time since last update (sec) */ - public UpdateEvent(double deltaTime) - { + public UpdateEvent(double deltaTime) { this.deltaTime = deltaTime; } diff --git a/src/mightypork/gamecore/control/events/gui/LayoutChangeEvent.java b/src/mightypork/gamecore/control/events/gui/LayoutChangeEvent.java new file mode 100644 index 0000000..62195e0 --- /dev/null +++ b/src/mightypork/gamecore/control/events/gui/LayoutChangeEvent.java @@ -0,0 +1,28 @@ +package mightypork.gamecore.control.events.gui; + + +import mightypork.util.control.eventbus.BusEvent; +import mightypork.util.control.eventbus.events.flags.ImmediateEvent; +import mightypork.util.control.eventbus.events.flags.NonConsumableEvent; + + +/** + * Intended use is to notify UI component sub-clients that they should poll + * their cached constraints. + * + * @author MightyPork + */ +@ImmediateEvent +@NonConsumableEvent +public class LayoutChangeEvent extends BusEvent { + + public LayoutChangeEvent() { + } + + + @Override + public void handleBy(LayoutChangeListener handler) + { + handler.onLayoutChanged(); + } +} diff --git a/src/mightypork/gamecore/control/events/gui/LayoutChangeListener.java b/src/mightypork/gamecore/control/events/gui/LayoutChangeListener.java new file mode 100644 index 0000000..9dd1cd9 --- /dev/null +++ b/src/mightypork/gamecore/control/events/gui/LayoutChangeListener.java @@ -0,0 +1,6 @@ +package mightypork.gamecore.control.events.gui; + +public interface LayoutChangeListener { + + public void onLayoutChanged(); +} \ No newline at end of file diff --git a/src/mightypork/gamecore/control/events/ViewportChangeEvent.java b/src/mightypork/gamecore/control/events/gui/ViewportChangeEvent.java similarity index 67% rename from src/mightypork/gamecore/control/events/ViewportChangeEvent.java rename to src/mightypork/gamecore/control/events/gui/ViewportChangeEvent.java index 25123ef..1d81929 100644 --- a/src/mightypork/gamecore/control/events/ViewportChangeEvent.java +++ b/src/mightypork/gamecore/control/events/gui/ViewportChangeEvent.java @@ -1,8 +1,9 @@ -package mightypork.gamecore.control.events; +package mightypork.gamecore.control.events.gui; import mightypork.util.constraints.vect.Vect; -import mightypork.util.control.eventbus.events.Event; +import mightypork.util.control.eventbus.BusEvent; +import mightypork.util.control.eventbus.events.flags.NonConsumableEvent; /** @@ -10,7 +11,8 @@ import mightypork.util.control.eventbus.events.Event; * * @author MightyPork */ -public class ViewportChangeEvent implements Event { +@NonConsumableEvent +public class ViewportChangeEvent extends BusEvent { private final boolean fullscreen; private final Vect screenSize; @@ -22,8 +24,7 @@ public class ViewportChangeEvent implements Event * @param fullscreen is now fullscreen * @param size new screen size */ - public ViewportChangeEvent(boolean fsChanged, boolean fullscreen, Vect size) - { + public ViewportChangeEvent(boolean fsChanged, boolean fullscreen, Vect size) { this.fullscreen = fullscreen; this.screenSize = size; this.fsChanged = fsChanged; @@ -58,23 +59,8 @@ public class ViewportChangeEvent implements Event @Override - public void handleBy(Listener handler) + public void handleBy(ViewportChangeListener handler) { handler.onViewportChanged(this); } - - /** - * {@link ViewportChangeEvent} listener - * - * @author MightyPork - */ - public interface Listener { - - /** - * Handle event - * - * @param event - */ - void onViewportChanged(ViewportChangeEvent event); - } } diff --git a/src/mightypork/gamecore/control/events/gui/ViewportChangeListener.java b/src/mightypork/gamecore/control/events/gui/ViewportChangeListener.java new file mode 100644 index 0000000..131001b --- /dev/null +++ b/src/mightypork/gamecore/control/events/gui/ViewportChangeListener.java @@ -0,0 +1,16 @@ +package mightypork.gamecore.control.events.gui; + +/** + * {@link ViewportChangeEvent} listener + * + * @author MightyPork + */ +public interface ViewportChangeListener { + + /** + * Handle event + * + * @param event + */ + void onViewportChanged(ViewportChangeEvent event); +} \ No newline at end of file diff --git a/src/mightypork/gamecore/control/events/KeyEvent.java b/src/mightypork/gamecore/control/events/input/KeyEvent.java similarity index 68% rename from src/mightypork/gamecore/control/events/KeyEvent.java rename to src/mightypork/gamecore/control/events/input/KeyEvent.java index ea03321..84a24a8 100644 --- a/src/mightypork/gamecore/control/events/KeyEvent.java +++ b/src/mightypork/gamecore/control/events/input/KeyEvent.java @@ -1,7 +1,7 @@ -package mightypork.gamecore.control.events; +package mightypork.gamecore.control.events.input; -import mightypork.util.control.eventbus.events.Event; +import mightypork.util.control.eventbus.BusEvent; import org.lwjgl.input.Keyboard; @@ -11,7 +11,7 @@ import org.lwjgl.input.Keyboard; * * @author MightyPork */ -public class KeyEvent implements Event { +public class KeyEvent extends BusEvent { private final int key; private final boolean down; @@ -23,8 +23,7 @@ public class KeyEvent implements Event { * @param c typed char (can be zero char) * @param down true = pressed, false = released. */ - public KeyEvent(int key, char c, boolean down) - { + public KeyEvent(int key, char c, boolean down) { this.key = key; this.c = c; this.down = down; @@ -68,27 +67,11 @@ public class KeyEvent implements Event { @Override - public void handleBy(Listener keh) + public void handleBy(KeyListener keh) { keh.receive(this); } - /** - * {@link KeyEvent} listener - * - * @author MightyPork - */ - public interface Listener { - - /** - * Handle an event - * - * @param event event - */ - void receive(KeyEvent event); - } - - @Override public String toString() { diff --git a/src/mightypork/gamecore/control/events/input/KeyListener.java b/src/mightypork/gamecore/control/events/input/KeyListener.java new file mode 100644 index 0000000..cfee519 --- /dev/null +++ b/src/mightypork/gamecore/control/events/input/KeyListener.java @@ -0,0 +1,16 @@ +package mightypork.gamecore.control.events.input; + +/** + * {@link KeyEvent} listener + * + * @author MightyPork + */ +public interface KeyListener { + + /** + * Handle an event + * + * @param event event + */ + void receive(KeyEvent event); +} \ No newline at end of file diff --git a/src/mightypork/gamecore/control/events/MouseButtonEvent.java b/src/mightypork/gamecore/control/events/input/MouseButtonEvent.java similarity index 81% rename from src/mightypork/gamecore/control/events/MouseButtonEvent.java rename to src/mightypork/gamecore/control/events/input/MouseButtonEvent.java index 924ef0a..d17b4b0 100644 --- a/src/mightypork/gamecore/control/events/MouseButtonEvent.java +++ b/src/mightypork/gamecore/control/events/input/MouseButtonEvent.java @@ -1,10 +1,10 @@ -package mightypork.gamecore.control.events; +package mightypork.gamecore.control.events.input; import mightypork.util.constraints.rect.proxy.RectBound; import mightypork.util.constraints.vect.Vect; import mightypork.util.constraints.vect.VectConst; -import mightypork.util.control.eventbus.events.Event; +import mightypork.util.control.eventbus.BusEvent; /** @@ -12,7 +12,7 @@ import mightypork.util.control.eventbus.events.Event; * * @author MightyPork */ -public class MouseButtonEvent implements Event { +public class MouseButtonEvent extends BusEvent { public static final int BUTTON_LEFT = 0; public static final int BUTTON_MIDDLE = 1; @@ -32,8 +32,7 @@ public class MouseButtonEvent implements Event { * @param down button pressed * @param wheeld wheel change */ - public MouseButtonEvent(Vect pos, int button, boolean down, int wheeld) - { + public MouseButtonEvent(Vect pos, int button, boolean down, int wheeld) { this.button = button; this.down = down; this.pos = pos.freeze(); @@ -117,23 +116,8 @@ public class MouseButtonEvent implements Event { @Override - public void handleBy(Listener handler) + public void handleBy(MouseButtonListener handler) { handler.receive(this); } - - /** - * {@link MouseButtonEvent} listener - * - * @author MightyPork - */ - public interface Listener { - - /** - * Handle an event - * - * @param event event - */ - void receive(MouseButtonEvent event); - } } diff --git a/src/mightypork/gamecore/control/events/input/MouseButtonListener.java b/src/mightypork/gamecore/control/events/input/MouseButtonListener.java new file mode 100644 index 0000000..eee8e58 --- /dev/null +++ b/src/mightypork/gamecore/control/events/input/MouseButtonListener.java @@ -0,0 +1,16 @@ +package mightypork.gamecore.control.events.input; + +/** + * {@link MouseButtonEvent} listener + * + * @author MightyPork + */ +public interface MouseButtonListener { + + /** + * Handle an event + * + * @param event event + */ + void receive(MouseButtonEvent event); +} \ No newline at end of file diff --git a/src/mightypork/gamecore/control/events/MouseMotionEvent.java b/src/mightypork/gamecore/control/events/input/MouseMotionEvent.java similarity index 58% rename from src/mightypork/gamecore/control/events/MouseMotionEvent.java rename to src/mightypork/gamecore/control/events/input/MouseMotionEvent.java index a05cf14..a744e63 100644 --- a/src/mightypork/gamecore/control/events/MouseMotionEvent.java +++ b/src/mightypork/gamecore/control/events/input/MouseMotionEvent.java @@ -1,9 +1,9 @@ -package mightypork.gamecore.control.events; +package mightypork.gamecore.control.events.input; import mightypork.util.constraints.vect.Vect; import mightypork.util.constraints.vect.VectConst; -import mightypork.util.control.eventbus.events.Event; +import mightypork.util.control.eventbus.BusEvent; import mightypork.util.control.eventbus.events.flags.UnloggedEvent; @@ -13,7 +13,7 @@ import mightypork.util.control.eventbus.events.flags.UnloggedEvent; * @author MightyPork */ @UnloggedEvent -public class MouseMotionEvent implements Event { +public class MouseMotionEvent extends BusEvent { private final VectConst move; private final VectConst pos; @@ -23,8 +23,7 @@ public class MouseMotionEvent implements Event { * @param pos end pos * @param move move vector */ - public MouseMotionEvent(Vect pos, Vect move) - { + public MouseMotionEvent(Vect pos, Vect move) { this.move = move.freeze(); this.pos = pos.freeze(); } @@ -49,24 +48,9 @@ public class MouseMotionEvent implements Event { @Override - public void handleBy(Listener keh) + public void handleBy(MouseMotionListener keh) { keh.receive(this); } - /** - * {@link MouseMotionEvent} listener - * - * @author MightyPork - */ - public interface Listener { - - /** - * Handle an event - * - * @param event event - */ - void receive(MouseMotionEvent event); - } - } diff --git a/src/mightypork/gamecore/control/events/input/MouseMotionListener.java b/src/mightypork/gamecore/control/events/input/MouseMotionListener.java new file mode 100644 index 0000000..01abc67 --- /dev/null +++ b/src/mightypork/gamecore/control/events/input/MouseMotionListener.java @@ -0,0 +1,16 @@ +package mightypork.gamecore.control.events.input; + +/** + * {@link MouseMotionEvent} listener + * + * @author MightyPork + */ +public interface MouseMotionListener { + + /** + * Handle an event + * + * @param event event + */ + void receive(MouseMotionEvent event); +} \ No newline at end of file diff --git a/src/mightypork/gamecore/control/events/requests/MainLoopRequest.java b/src/mightypork/gamecore/control/events/requests/MainLoopRequest.java new file mode 100644 index 0000000..7de48ce --- /dev/null +++ b/src/mightypork/gamecore/control/events/requests/MainLoopRequest.java @@ -0,0 +1,32 @@ +package mightypork.gamecore.control.events.requests; + + +import mightypork.util.control.eventbus.BusEvent; +import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent; + + +/** + * Request to execute given {@link Runnable} in main loop. + * + * @author MightyPork + */ +@SingleReceiverEvent +public class MainLoopRequest extends BusEvent { + + private final Runnable task; + + + /** + * @param task task to run on main thread in rendering context + */ + public MainLoopRequest(Runnable task) { + this.task = task; + } + + + @Override + public void handleBy(MainLoopRequestListener handler) + { + handler.queueTask(task); + } +} diff --git a/src/mightypork/gamecore/control/events/requests/MainLoopRequestListener.java b/src/mightypork/gamecore/control/events/requests/MainLoopRequestListener.java new file mode 100644 index 0000000..913a167 --- /dev/null +++ b/src/mightypork/gamecore/control/events/requests/MainLoopRequestListener.java @@ -0,0 +1,16 @@ +package mightypork.gamecore.control.events.requests; + +/** + * {@link MainLoopRequest} listener + * + * @author MightyPork + */ +public interface MainLoopRequestListener { + + /** + * Perform the requested action + * + * @param request + */ + void queueTask(Runnable request); +} \ No newline at end of file diff --git a/src/mightypork/gamecore/control/events/requests/ResourceLoadRequest.java b/src/mightypork/gamecore/control/events/requests/ResourceLoadRequest.java new file mode 100644 index 0000000..011a73c --- /dev/null +++ b/src/mightypork/gamecore/control/events/requests/ResourceLoadRequest.java @@ -0,0 +1,33 @@ +package mightypork.gamecore.control.events.requests; + + +import mightypork.gamecore.loading.Deferred; +import mightypork.util.control.eventbus.BusEvent; +import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent; + + +/** + * Request to load a deferred resource. + * + * @author MightyPork + */ +@SingleReceiverEvent +public class ResourceLoadRequest extends BusEvent { + + private final Deferred resource; + + + /** + * @param resource resource to load + */ + public ResourceLoadRequest(Deferred resource) { + this.resource = resource; + } + + + @Override + public void handleBy(ResourceLoadRequestListener handler) + { + handler.loadResource(resource); + } +} diff --git a/src/mightypork/gamecore/control/events/requests/ResourceLoadRequestListener.java b/src/mightypork/gamecore/control/events/requests/ResourceLoadRequestListener.java new file mode 100644 index 0000000..db550a0 --- /dev/null +++ b/src/mightypork/gamecore/control/events/requests/ResourceLoadRequestListener.java @@ -0,0 +1,18 @@ +package mightypork.gamecore.control.events.requests; + +import mightypork.gamecore.loading.Deferred; + +/** + * {@link ResourceLoadRequest} listener + * + * @author MightyPork + */ +public interface ResourceLoadRequestListener { + + /** + * Load a resource + * + * @param resource + */ + void loadResource(Deferred resource); +} \ No newline at end of file diff --git a/src/mightypork/gamecore/control/events/requests/ScreenRequestEvent.java b/src/mightypork/gamecore/control/events/requests/ScreenRequestEvent.java new file mode 100644 index 0000000..a2504b3 --- /dev/null +++ b/src/mightypork/gamecore/control/events/requests/ScreenRequestEvent.java @@ -0,0 +1,33 @@ +package mightypork.gamecore.control.events.requests; + + +import mightypork.util.control.eventbus.BusEvent; +import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent; + + +/** + * Request to change screen + * + * @author MightyPork + */ +@SingleReceiverEvent +public class ScreenRequestEvent extends BusEvent { + + private final String scrName; + + + /** + * @param screenKey screen name + */ + public ScreenRequestEvent(String screenKey) { + scrName = screenKey; + } + + + @Override + public void handleBy(ScreenRequestListener handler) + { + handler.showScreen(scrName); + } + +} diff --git a/src/mightypork/gamecore/control/events/requests/ScreenRequestListener.java b/src/mightypork/gamecore/control/events/requests/ScreenRequestListener.java new file mode 100644 index 0000000..1f3655d --- /dev/null +++ b/src/mightypork/gamecore/control/events/requests/ScreenRequestListener.java @@ -0,0 +1,14 @@ +package mightypork.gamecore.control.events.requests; + +/** + * {@link ScreenRequestEvent} listener + * + * @author MightyPork + */ +public interface ScreenRequestListener { + + /** + * @param key screen to show + */ + void showScreen(String key); +} \ No newline at end of file diff --git a/src/mightypork/gamecore/gui/components/ClickableComponent.java b/src/mightypork/gamecore/gui/components/ClickableComponent.java index d76719f..3cdd747 100644 --- a/src/mightypork/gamecore/gui/components/ClickableComponent.java +++ b/src/mightypork/gamecore/gui/components/ClickableComponent.java @@ -1,12 +1,13 @@ package mightypork.gamecore.gui.components; -import mightypork.gamecore.control.events.MouseButtonEvent; +import mightypork.gamecore.control.events.input.MouseButtonEvent; +import mightypork.gamecore.control.events.input.MouseButtonListener; import mightypork.util.control.Action; import mightypork.util.control.ActionTrigger; -public abstract class ClickableComponent extends InputComponent implements ActionTrigger, MouseButtonEvent.Listener { +public abstract class ClickableComponent extends InputComponent implements ActionTrigger, MouseButtonListener { private boolean btnDownOver; private Action action; @@ -38,6 +39,7 @@ public abstract class ClickableComponent extends InputComponent implements Actio if (btnDownOver && event.isOver(this)) { triggerAction(); + event.consume(); } btnDownOver = false; diff --git a/src/mightypork/gamecore/gui/components/VisualComponent.java b/src/mightypork/gamecore/gui/components/VisualComponent.java index 4f81b12..c4b5d1e 100644 --- a/src/mightypork/gamecore/gui/components/VisualComponent.java +++ b/src/mightypork/gamecore/gui/components/VisualComponent.java @@ -1,7 +1,8 @@ package mightypork.gamecore.gui.components; -import mightypork.gamecore.control.events.LayoutChangeEvent; +import mightypork.gamecore.control.events.gui.LayoutChangeEvent; +import mightypork.gamecore.control.events.gui.LayoutChangeListener; import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.render.Renderable; import mightypork.util.annotations.DefaultImpl; @@ -17,7 +18,7 @@ import mightypork.util.constraints.rect.proxy.RectBoundAdapter; * * @author MightyPork */ -public abstract class VisualComponent extends AbstractRectCache implements Component, LayoutChangeEvent.Listener { +public abstract class VisualComponent extends AbstractRectCache implements Component, LayoutChangeListener { private Rect source; private boolean visible = true; diff --git a/src/mightypork/gamecore/gui/screens/BaseScreen.java b/src/mightypork/gamecore/gui/screens/BaseScreen.java index 55433f7..b613546 100644 --- a/src/mightypork/gamecore/gui/screens/BaseScreen.java +++ b/src/mightypork/gamecore/gui/screens/BaseScreen.java @@ -3,7 +3,8 @@ package mightypork.gamecore.gui.screens; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppSubModule; -import mightypork.gamecore.control.events.LayoutChangeEvent; +import mightypork.gamecore.control.events.gui.LayoutChangeEvent; +import mightypork.gamecore.control.events.gui.LayoutChangeListener; import mightypork.gamecore.input.KeyBinder; import mightypork.gamecore.input.KeyBindingPool; import mightypork.gamecore.input.KeyStroke; @@ -17,7 +18,7 @@ import mightypork.util.constraints.rect.Rect; * * @author MightyPork */ -public abstract class BaseScreen extends AppSubModule implements Screen, KeyBinder, LayoutChangeEvent.Listener { +public abstract class BaseScreen extends AppSubModule implements Screen, KeyBinder, LayoutChangeListener { private final KeyBindingPool keybindings = new KeyBindingPool(); diff --git a/src/mightypork/gamecore/gui/screens/LayeredScreen.java b/src/mightypork/gamecore/gui/screens/LayeredScreen.java index 45d510c..7474283 100644 --- a/src/mightypork/gamecore/gui/screens/LayeredScreen.java +++ b/src/mightypork/gamecore/gui/screens/LayeredScreen.java @@ -2,9 +2,12 @@ package mightypork.gamecore.gui.screens; import java.util.Collection; +import java.util.Comparator; import java.util.TreeSet; import mightypork.gamecore.control.AppAccess; +import mightypork.util.control.eventbus.clients.DelegatingClient; +import mightypork.util.control.eventbus.clients.RootBusNode; /** @@ -14,22 +17,59 @@ import mightypork.gamecore.control.AppAccess; */ public abstract class LayeredScreen extends BaseScreen { - private final Collection layers = new TreeSet<>(); + private class LayersClient implements DelegatingClient { + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public Collection getChildClients() + { + return layersByEventPriority; + } + + @Override + public boolean doesDelegate() + { + return true; + } + + } + + private final Collection layersByZIndex = new TreeSet<>(new Comparator() { + + @Override + public int compare(Overlay o1, Overlay o2) + { + return o1.getZIndex() - o2.getZIndex(); + } + + }); + + private final Collection layersByEventPriority = new TreeSet<>(new Comparator() { + + @Override + public int compare(Overlay o1, Overlay o2) + { + return o2.getEventPriority() - o1.getEventPriority(); + } + + }); + + private final LayersClient layersClient = new LayersClient(); /** * @param app app access */ - public LayeredScreen(AppAccess app) - { + public LayeredScreen(AppAccess app) { super(app); + addChildClient(layersClient); } @Override protected void renderScreen() { - for (final ScreenLayer layer : layers) { + for (final ScreenLayer layer : layersByZIndex) { if (layer.isVisible()) layer.render(); } } @@ -42,15 +82,15 @@ public abstract class LayeredScreen extends BaseScreen { */ protected void addLayer(ScreenLayer layer) { - this.layers.add(layer); - addChildClient(layer); + this.layersByZIndex.add(layer); + this.layersByEventPriority.add(layer); } @Override protected void onScreenEnter() { - for (final ScreenLayer layer : layers) { + for (final ScreenLayer layer : layersByEventPriority) { layer.onScreenEnter(); } } @@ -59,7 +99,7 @@ public abstract class LayeredScreen extends BaseScreen { @Override protected void onScreenLeave() { - for (final ScreenLayer layer : layers) { + for (final ScreenLayer layer : layersByEventPriority) { layer.onScreenLeave(); } } diff --git a/src/mightypork/gamecore/gui/screens/Overlay.java b/src/mightypork/gamecore/gui/screens/Overlay.java index 6ec6e19..c629c28 100644 --- a/src/mightypork/gamecore/gui/screens/Overlay.java +++ b/src/mightypork/gamecore/gui/screens/Overlay.java @@ -6,7 +6,7 @@ import java.util.LinkedHashSet; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppSubModule; -import mightypork.gamecore.control.events.LayoutChangeEvent; +import mightypork.gamecore.control.events.gui.LayoutChangeListener; import mightypork.gamecore.gui.Hideable; import mightypork.gamecore.gui.components.layout.ConstraintLayout; import mightypork.gamecore.input.KeyBinder; @@ -24,7 +24,7 @@ import mightypork.util.control.timing.Updateable; * * @author MightyPork */ -public abstract class Overlay extends AppSubModule implements Updateable, Comparable, Renderable, KeyBinder, Hideable, LayoutChangeEvent.Listener { +public abstract class Overlay extends AppSubModule implements Comparable, Updateable, Renderable, KeyBinder, Hideable, LayoutChangeListener { private boolean visible = true; private final KeyBindingPool keybindings = new KeyBindingPool(); @@ -42,8 +42,7 @@ public abstract class Overlay extends AppSubModule implements Updateable, Compar protected final Collection updated = new LinkedHashSet<>(); - public Overlay(AppAccess app) - { + public Overlay(AppAccess app) { super(app); this.mouse = getInput().getMousePos(); @@ -84,20 +83,24 @@ public abstract class Overlay extends AppSubModule implements Updateable, Compar } - @Override - public final int compareTo(Overlay o) - { - return getPriority() - o.getPriority(); - } - - /** - * Get rendering priority + * Get rendering layer * * @return higher = on top. */ @DefaultImpl - public abstract int getPriority(); + public abstract int getZIndex(); + + + /** + * Get event bus listening priority - useful to block incoming events. + * + * @return higher = first. + */ + public int getEventPriority() + { + return getZIndex(); + } /** @@ -120,6 +123,12 @@ public abstract class Overlay extends AppSubModule implements Updateable, Compar } } + @Override + public int compareTo(Overlay o) + { + return o.getEventPriority() - getEventPriority(); + } + /** *

diff --git a/src/mightypork/gamecore/gui/screens/ScreenRegistry.java b/src/mightypork/gamecore/gui/screens/ScreenRegistry.java index 0bbcea4..3261052 100644 --- a/src/mightypork/gamecore/gui/screens/ScreenRegistry.java +++ b/src/mightypork/gamecore/gui/screens/ScreenRegistry.java @@ -8,9 +8,10 @@ import java.util.TreeSet; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppModule; -import mightypork.gamecore.control.events.LayoutChangeEvent; -import mightypork.gamecore.control.events.ScreenRequestEvent; -import mightypork.gamecore.control.events.ViewportChangeEvent; +import mightypork.gamecore.control.events.gui.LayoutChangeEvent; +import mightypork.gamecore.control.events.gui.ViewportChangeEvent; +import mightypork.gamecore.control.events.gui.ViewportChangeListener; +import mightypork.gamecore.control.events.requests.ScreenRequestListener; import mightypork.gamecore.render.Renderable; import mightypork.util.annotations.DefaultImpl; import mightypork.util.logging.Log; @@ -21,7 +22,7 @@ import mightypork.util.logging.Log; * * @author MightyPork */ -public class ScreenRegistry extends AppModule implements ScreenRequestEvent.Listener, ViewportChangeEvent.Listener, Renderable { +public class ScreenRegistry extends AppModule implements ScreenRequestListener, ViewportChangeListener, Renderable { private final Map screens = new HashMap<>(); private final Collection overlays = new TreeSet<>(); diff --git a/src/mightypork/gamecore/input/InputSystem.java b/src/mightypork/gamecore/input/InputSystem.java index c018702..eb5c49c 100644 --- a/src/mightypork/gamecore/input/InputSystem.java +++ b/src/mightypork/gamecore/input/InputSystem.java @@ -2,9 +2,9 @@ package mightypork.gamecore.input; import mightypork.gamecore.control.AppAccess; -import mightypork.gamecore.control.events.KeyEvent; -import mightypork.gamecore.control.events.MouseButtonEvent; -import mightypork.gamecore.control.events.MouseMotionEvent; +import mightypork.gamecore.control.events.input.KeyEvent; +import mightypork.gamecore.control.events.input.MouseButtonEvent; +import mightypork.gamecore.control.events.input.MouseMotionEvent; import mightypork.rogue.events.ActionRequest; import mightypork.rogue.events.ActionRequest.RequestType; import mightypork.util.constraints.vect.Vect; diff --git a/src/mightypork/gamecore/input/KeyBinding.java b/src/mightypork/gamecore/input/KeyBinding.java index 50e8984..226e196 100644 --- a/src/mightypork/gamecore/input/KeyBinding.java +++ b/src/mightypork/gamecore/input/KeyBinding.java @@ -1,7 +1,8 @@ package mightypork.gamecore.input; -import mightypork.gamecore.control.events.KeyEvent; +import mightypork.gamecore.control.events.input.KeyEvent; +import mightypork.gamecore.control.events.input.KeyListener; /** @@ -9,7 +10,7 @@ import mightypork.gamecore.control.events.KeyEvent; * * @author MightyPork */ -public class KeyBinding implements KeyEvent.Listener { +public class KeyBinding implements KeyListener { private final KeyStroke keystroke; private Runnable handler; diff --git a/src/mightypork/gamecore/input/KeyBindingPool.java b/src/mightypork/gamecore/input/KeyBindingPool.java index 0ee346d..ab77c0c 100644 --- a/src/mightypork/gamecore/input/KeyBindingPool.java +++ b/src/mightypork/gamecore/input/KeyBindingPool.java @@ -5,7 +5,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import mightypork.gamecore.control.events.KeyEvent; +import mightypork.gamecore.control.events.input.KeyEvent; +import mightypork.gamecore.control.events.input.KeyListener; import mightypork.util.logging.Log; @@ -14,7 +15,7 @@ import mightypork.util.logging.Log; * * @author MightyPork */ -public class KeyBindingPool implements KeyBinder, KeyEvent.Listener { +public class KeyBindingPool implements KeyBinder, KeyListener { private final Set bindings = new HashSet<>(); diff --git a/src/mightypork/gamecore/loading/AsyncResourceLoader.java b/src/mightypork/gamecore/loading/AsyncResourceLoader.java index b4c43c0..77a49ac 100644 --- a/src/mightypork/gamecore/loading/AsyncResourceLoader.java +++ b/src/mightypork/gamecore/loading/AsyncResourceLoader.java @@ -5,8 +5,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; -import mightypork.gamecore.control.events.MainLoopTaskRequest; -import mightypork.gamecore.control.events.ResourceLoadRequest; +import mightypork.gamecore.control.events.requests.MainLoopRequest; +import mightypork.gamecore.control.events.requests.ResourceLoadRequestListener; import mightypork.util.annotations.FactoryMethod; import mightypork.util.control.Destroyable; import mightypork.util.control.eventbus.BusAccess; @@ -18,7 +18,7 @@ import mightypork.util.logging.Log; * * @author MightyPork */ -public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.Listener, Destroyable { +public class AsyncResourceLoader extends Thread implements ResourceLoadRequestListener, Destroyable { /** * Start a new loader thread. @@ -73,7 +73,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L } else { Log.f3(" Delegating to main thread:\n " + Log.str(resource)); - app.getEventBus().send(new MainLoopTaskRequest(new Runnable() { + app.getEventBus().send(new MainLoopRequest(new Runnable() { @Override public void run() diff --git a/src/mightypork/gamecore/render/DisplaySystem.java b/src/mightypork/gamecore/render/DisplaySystem.java index 39e3ec5..9cdae4c 100644 --- a/src/mightypork/gamecore/render/DisplaySystem.java +++ b/src/mightypork/gamecore/render/DisplaySystem.java @@ -7,7 +7,7 @@ import java.nio.ByteBuffer; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppModule; -import mightypork.gamecore.control.events.ViewportChangeEvent; +import mightypork.gamecore.control.events.gui.ViewportChangeEvent; import mightypork.util.constraints.rect.Rect; import mightypork.util.constraints.rect.proxy.RectBound; import mightypork.util.constraints.vect.Vect; diff --git a/src/mightypork/gamecore/render/fonts/FontBank.java b/src/mightypork/gamecore/render/fonts/FontBank.java index 8fafccc..cf53858 100644 --- a/src/mightypork/gamecore/render/fonts/FontBank.java +++ b/src/mightypork/gamecore/render/fonts/FontBank.java @@ -5,7 +5,7 @@ import java.util.HashMap; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAdapter; -import mightypork.gamecore.control.events.ResourceLoadRequest; +import mightypork.gamecore.control.events.requests.ResourceLoadRequest; import mightypork.gamecore.render.fonts.impl.DeferredFont; import org.newdawn.slick.opengl.Texture; diff --git a/src/mightypork/gamecore/render/textures/TextureBank.java b/src/mightypork/gamecore/render/textures/TextureBank.java index 11dcc67..9b6b823 100644 --- a/src/mightypork/gamecore/render/textures/TextureBank.java +++ b/src/mightypork/gamecore/render/textures/TextureBank.java @@ -6,7 +6,7 @@ import java.util.Map; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAdapter; -import mightypork.gamecore.control.events.ResourceLoadRequest; +import mightypork.gamecore.control.events.requests.ResourceLoadRequest; import mightypork.util.constraints.rect.Rect; import mightypork.util.error.KeyAlreadyExistsException; diff --git a/src/mightypork/rogue/App.java b/src/mightypork/rogue/App.java index 9e24342..680183a 100644 --- a/src/mightypork/rogue/App.java +++ b/src/mightypork/rogue/App.java @@ -26,8 +26,8 @@ import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.item.Item; import mightypork.rogue.world.level.Level; import mightypork.rogue.world.tile.Tile; +import mightypork.util.control.eventbus.BusEvent; import mightypork.util.control.eventbus.EventBus; -import mightypork.util.control.eventbus.events.Event; import mightypork.util.ion.Ion; import mightypork.util.logging.Log; import mightypork.util.logging.writers.LogWriter; @@ -139,7 +139,7 @@ public final class App extends BaseApp { } - private void bindToKey(final Event event, int... keys) + private void bindToKey(final BusEvent event, int... keys) { getInput().bindKey(new KeyStroke(keys), new Runnable() { diff --git a/src/mightypork/rogue/events/ActionRequest.java b/src/mightypork/rogue/events/ActionRequest.java index 3390d90..e757b65 100644 --- a/src/mightypork/rogue/events/ActionRequest.java +++ b/src/mightypork/rogue/events/ActionRequest.java @@ -1,7 +1,7 @@ package mightypork.rogue.events; -import mightypork.util.control.eventbus.events.Event; +import mightypork.util.control.eventbus.BusEvent; import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent; @@ -11,7 +11,7 @@ import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent; * @author MightyPork */ @SingleReceiverEvent -public class ActionRequest implements Event { +public class ActionRequest extends BusEvent { private final RequestType type; diff --git a/src/mightypork/rogue/screens/CrossfadeOverlay.java b/src/mightypork/rogue/screens/CrossfadeOverlay.java index 779c7a2..9222a64 100644 --- a/src/mightypork/rogue/screens/CrossfadeOverlay.java +++ b/src/mightypork/rogue/screens/CrossfadeOverlay.java @@ -2,7 +2,7 @@ package mightypork.rogue.screens; import mightypork.gamecore.control.AppAccess; -import mightypork.gamecore.control.events.ScreenRequestEvent; +import mightypork.gamecore.control.events.requests.ScreenRequestEvent; import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.screens.Overlay; import mightypork.rogue.events.ActionRequest; @@ -62,7 +62,7 @@ public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listen @Override - public int getPriority() + public int getZIndex() { return Integer.MAX_VALUE - 1; // let FPS go on top } diff --git a/src/mightypork/rogue/screens/CrossfadeRequest.java b/src/mightypork/rogue/screens/CrossfadeRequest.java index 8863ed4..70b2e78 100644 --- a/src/mightypork/rogue/screens/CrossfadeRequest.java +++ b/src/mightypork/rogue/screens/CrossfadeRequest.java @@ -1,13 +1,13 @@ package mightypork.rogue.screens; -import mightypork.util.control.eventbus.events.Event; +import mightypork.util.control.eventbus.BusEvent; /** * @author MightyPork */ -public class CrossfadeRequest implements Event { +public class CrossfadeRequest extends BusEvent { private final String screen; diff --git a/src/mightypork/rogue/screens/FpsOverlay.java b/src/mightypork/rogue/screens/FpsOverlay.java index ac91df0..1171e20 100644 --- a/src/mightypork/rogue/screens/FpsOverlay.java +++ b/src/mightypork/rogue/screens/FpsOverlay.java @@ -60,7 +60,7 @@ public class FpsOverlay extends Overlay { @Override - public int getPriority() + public int getZIndex() { return Integer.MAX_VALUE; } diff --git a/src/mightypork/rogue/screens/gamescreen/GameGui.java b/src/mightypork/rogue/screens/gamescreen/HudLayer.java similarity index 89% rename from src/mightypork/rogue/screens/gamescreen/GameGui.java rename to src/mightypork/rogue/screens/gamescreen/HudLayer.java index b123fcf..1fe5d4c 100644 --- a/src/mightypork/rogue/screens/gamescreen/GameGui.java +++ b/src/mightypork/rogue/screens/gamescreen/HudLayer.java @@ -7,13 +7,15 @@ import mightypork.gamecore.gui.components.painters.ImagePainter; import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.rogue.Res; +import mightypork.rogue.screens.gamescreen.gui.HeartBar; +import mightypork.rogue.screens.gamescreen.gui.NavItemSlot; import mightypork.util.constraints.num.Num; import mightypork.util.constraints.rect.Rect; -public class GameGui extends ScreenLayer { +public class HudLayer extends ScreenLayer { - public GameGui(Screen screen) + public HudLayer(Screen screen) { super(screen); @@ -48,7 +50,7 @@ public class GameGui extends ScreenLayer { @Override - public int getPriority() + public int getZIndex() { return 100; } diff --git a/src/mightypork/rogue/screens/gamescreen/ScreenGame.java b/src/mightypork/rogue/screens/gamescreen/ScreenGame.java index 0de6641..e7e1cc3 100644 --- a/src/mightypork/rogue/screens/gamescreen/ScreenGame.java +++ b/src/mightypork/rogue/screens/gamescreen/ScreenGame.java @@ -1,18 +1,60 @@ package mightypork.rogue.screens.gamescreen; +import java.io.File; +import java.io.IOException; +import java.util.Random; + import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.gui.screens.LayeredScreen; +import mightypork.rogue.Paths; +import mightypork.rogue.world.MapGenerator; +import mightypork.rogue.world.World; +import mightypork.util.ion.Ion; public class ScreenGame extends LayeredScreen { - public ScreenGame(AppAccess app) - { + public ScreenGame(AppAccess app) { super(app); - addLayer(new WorldLayer(this)); //TODO with provided world - addLayer(new GameGui(this)); + addLayer(new WorldLayer(this, obtainWorld())); //TODO with provided world + addLayer(new HudLayer(this)); + } + + + private World obtainWorld() + { + + // FIXME just temporary test here + + final Random rand = new Random(); + final File f = new File(Paths.WORKDIR, "test-world.ion"); + + // SAVE + + World world = MapGenerator.createWorld(rand.nextLong()); + addChildClient(world); + + try { + Ion.toFile(f, world); + } catch (final IOException e) { + e.printStackTrace(); + } + + // LOAD + +// final World w; +// +// try { +// world = Ion.fromFile(f, World.class); +// } catch (IOException e) { +// e.printStackTrace(); +// System.exit(1); +// return; +// } + + return world; } diff --git a/src/mightypork/rogue/screens/gamescreen/WRBasicControls.java b/src/mightypork/rogue/screens/gamescreen/WRBasicControls.java deleted file mode 100644 index 59d090e..0000000 --- a/src/mightypork/rogue/screens/gamescreen/WRBasicControls.java +++ /dev/null @@ -1,115 +0,0 @@ -package mightypork.rogue.screens.gamescreen; - - -import mightypork.rogue.world.PlayerControl; -import mightypork.rogue.world.World; -import mightypork.rogue.world.WorldPos; -import mightypork.rogue.world.entity.Entity; -import mightypork.rogue.world.entity.models.EntityMoveListener; -import mightypork.rogue.world.level.Level; -import mightypork.util.constraints.vect.Vect; -import mightypork.util.math.Polar; -import mightypork.util.math.Calc.Deg; -import mightypork.gamecore.control.events.KeyEvent; -import mightypork.gamecore.control.events.MouseButtonEvent; -import mightypork.gamecore.input.InputSystem; -import mightypork.gamecore.input.Keys; - - -public class WRBasicControls extends WorldRenderComponent implements KeyEvent.Listener, MouseButtonEvent.Listener, EntityMoveListener { - - private final PlayerControl pc; - - - public WRBasicControls(World world) { - super(world); - pc = world.getPlayerControl(); - pc.addMoveListener(this); - } - - - private void handleHeldKey() - { - if (InputSystem.isKeyDown(Keys.LEFT)) { - pc.walkWest(); - } else if (InputSystem.isKeyDown(Keys.RIGHT)) { - pc.walkEast(); - } else if (InputSystem.isKeyDown(Keys.UP)) { - pc.walkNorth(); - } else if (InputSystem.isKeyDown(Keys.DOWN)) { - pc.walkSouth(); - } - - if(InputSystem.isMouseButtonDown(0)) { - walkByMouse(InputSystem.getMousePos()); - } - } - - - @Override - public void onStepFinished(Entity entity, World world, Level level) - { - handleHeldKey(); - } - - - @Override - public void onPathFinished(Entity entity, World world, Level level) - { - handleHeldKey(); - } - - - @Override - public void onPathInterrupted(Entity entity, World world, Level level) - { - handleHeldKey(); - } - - - @Override - public void receive(MouseButtonEvent event) - { - if (!event.isDown()) return; - - walkByMouse(event.getPos()); - } - - - private void walkByMouse(Vect mouse) - { - - WorldPos clicked = toWorldPos(mouse); - WorldPos plpos = pc.getPos(); - - Polar p = Polar.fromCoord(clicked.x - plpos.x, clicked.y - plpos.y); - - int dir = Deg.round90(p.getAngleDeg()) / 90; - - switch (dir) { - case 0: - pc.walkEast(); - return; - - case 1: - pc.walkSouth(); - return; - - case 2: - pc.walkWest(); - return; - - case 3: - pc.walkNorth(); - return; - } - } - - - @Override - public void receive(KeyEvent event) - { - handleHeldKey(); - } - -} diff --git a/src/mightypork/rogue/screens/gamescreen/WorldLayer.java b/src/mightypork/rogue/screens/gamescreen/WorldLayer.java index b1bcfd7..3b558a8 100644 --- a/src/mightypork/rogue/screens/gamescreen/WorldLayer.java +++ b/src/mightypork/rogue/screens/gamescreen/WorldLayer.java @@ -1,64 +1,31 @@ package mightypork.rogue.screens.gamescreen; -import java.io.File; -import java.io.IOException; -import java.util.Random; - -import mightypork.gamecore.gui.components.InputComponent; import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.ScreenLayer; -import mightypork.rogue.Paths; -import mightypork.rogue.world.MapGenerator; +import mightypork.rogue.screens.gamescreen.world.MIPKeyWalk; +import mightypork.rogue.screens.gamescreen.world.MIPMouseWalk; +import mightypork.rogue.screens.gamescreen.world.MapView; import mightypork.rogue.world.World; import mightypork.util.constraints.num.Num; -import mightypork.util.ion.Ion; public class WorldLayer extends ScreenLayer { - private World world; - private InputComponent worldView; + private MapView worldView; - public WorldLayer(Screen screen) { - super(screen); - - // FIXME just temporary test here - - final Random rand = new Random(); - final File f = new File(Paths.WORKDIR, "test-world.ion"); - - // SAVE - - world = MapGenerator.createWorld(rand.nextLong()); - updated.add(world); - - try { - Ion.toFile(f, world); - } catch (final IOException e) { - e.printStackTrace(); - System.exit(1); // fail - return; - } - - // LOAD - -// final World w; -// -// try { -// world = Ion.fromFile(f, World.class); -// } catch (IOException e) { -// e.printStackTrace(); -// System.exit(1); -// return; -// } + public WorldLayer(Screen screen, World world) { + super(screen); + // render component + worldView = new MapView(world); - // render component + // map input plugins + worldView.addPlugin(new MIPKeyWalk()); + worldView.addPlugin(new MIPMouseWalk()); - worldView = new WRBasicControls(world); // size of lower navbar final Num lownav = root.width().min(root.height()).max(700).perc(7); @@ -69,7 +36,7 @@ public class WorldLayer extends ScreenLayer { @Override - public int getPriority() + public int getZIndex() { return -1; // stay down } diff --git a/src/mightypork/rogue/screens/gamescreen/WorldRenderComponent.java b/src/mightypork/rogue/screens/gamescreen/WorldRenderComponent.java deleted file mode 100644 index c07751f..0000000 --- a/src/mightypork/rogue/screens/gamescreen/WorldRenderComponent.java +++ /dev/null @@ -1,44 +0,0 @@ -package mightypork.rogue.screens.gamescreen; - - -import mightypork.gamecore.gui.components.InputComponent; -import mightypork.rogue.world.World; -import mightypork.rogue.world.WorldPos; -import mightypork.rogue.world.WorldRenderer; -import mightypork.util.constraints.vect.Vect; - - -public class WorldRenderComponent extends InputComponent { - - protected final WorldRenderer worldRenderer; - protected final World world; - - - public WorldRenderComponent(World world) { - this.world = world; - this.worldRenderer = new WorldRenderer(world, this, 8, 6, 72); - } - - - @Override - protected void renderComponent() - { - worldRenderer.render(); - } - - - @Override - public void updateLayout() - { - worldRenderer.poll(); // update sizing - } - - - /** - * Get tile coord at a screen position - */ - public WorldPos toWorldPos(Vect pos) - { - return worldRenderer.getClickedTile(pos); - } -} diff --git a/src/mightypork/rogue/screens/gamescreen/HeartBar.java b/src/mightypork/rogue/screens/gamescreen/gui/HeartBar.java similarity index 96% rename from src/mightypork/rogue/screens/gamescreen/HeartBar.java rename to src/mightypork/rogue/screens/gamescreen/gui/HeartBar.java index 7d00a1e..8cdd7c6 100644 --- a/src/mightypork/rogue/screens/gamescreen/HeartBar.java +++ b/src/mightypork/rogue/screens/gamescreen/gui/HeartBar.java @@ -1,4 +1,4 @@ -package mightypork.rogue.screens.gamescreen; +package mightypork.rogue.screens.gamescreen.gui; import mightypork.gamecore.gui.AlignX; diff --git a/src/mightypork/rogue/screens/gamescreen/NavItemSlot.java b/src/mightypork/rogue/screens/gamescreen/gui/NavItemSlot.java similarity index 89% rename from src/mightypork/rogue/screens/gamescreen/NavItemSlot.java rename to src/mightypork/rogue/screens/gamescreen/gui/NavItemSlot.java index b9874ea..f6b7701 100644 --- a/src/mightypork/rogue/screens/gamescreen/NavItemSlot.java +++ b/src/mightypork/rogue/screens/gamescreen/gui/NavItemSlot.java @@ -1,7 +1,8 @@ -package mightypork.rogue.screens.gamescreen; +package mightypork.rogue.screens.gamescreen.gui; -import mightypork.gamecore.control.events.MouseMotionEvent; +import mightypork.gamecore.control.events.input.MouseMotionEvent; +import mightypork.gamecore.control.events.input.MouseMotionListener; import mightypork.gamecore.gui.components.ClickableComponent; import mightypork.gamecore.render.Render; import mightypork.gamecore.render.textures.TxQuad; @@ -15,7 +16,7 @@ import mightypork.util.control.timing.Updateable; import mightypork.util.math.Easing; -public class NavItemSlot extends ClickableComponent implements MouseMotionEvent.Listener, Updateable { +public class NavItemSlot extends ClickableComponent implements MouseMotionListener, Updateable { private final TxQuad image; private final TxQuad frame; diff --git a/src/mightypork/rogue/screens/gamescreen/world/MIPKeyWalk.java b/src/mightypork/rogue/screens/gamescreen/world/MIPKeyWalk.java new file mode 100644 index 0000000..f77f4bb --- /dev/null +++ b/src/mightypork/rogue/screens/gamescreen/world/MIPKeyWalk.java @@ -0,0 +1,45 @@ +package mightypork.rogue.screens.gamescreen.world; + + +import mightypork.gamecore.input.InputSystem; +import mightypork.gamecore.input.Keys; +import mightypork.rogue.world.PlayerControl; +import mightypork.util.constraints.vect.Vect; + + +public class MIPKeyWalk implements MapInteractionPlugin { + + @Override + public void onStepEnd(MapView wv, PlayerControl player) + { + walkByKey(player); + } + + + @Override + public void onClick(MapView wv, PlayerControl player, Vect mouse) + { + } + + + @Override + public void onKey(MapView wv, PlayerControl player, int key) + { + walkByKey(player); + } + + + private void walkByKey(PlayerControl player) + { + if (InputSystem.isKeyDown(Keys.LEFT)) { + player.goWest(); + } else if (InputSystem.isKeyDown(Keys.RIGHT)) { + player.goEast(); + } else if (InputSystem.isKeyDown(Keys.UP)) { + player.goNorth(); + } else if (InputSystem.isKeyDown(Keys.DOWN)) { + player.goSouth(); + } + } + +} diff --git a/src/mightypork/rogue/screens/gamescreen/world/MIPMouseWalk.java b/src/mightypork/rogue/screens/gamescreen/world/MIPMouseWalk.java new file mode 100644 index 0000000..b5cb85a --- /dev/null +++ b/src/mightypork/rogue/screens/gamescreen/world/MIPMouseWalk.java @@ -0,0 +1,59 @@ +package mightypork.rogue.screens.gamescreen.world; + + +import mightypork.gamecore.input.InputSystem; +import mightypork.rogue.world.PlayerControl; +import mightypork.rogue.world.WorldPos; +import mightypork.util.constraints.vect.Vect; +import mightypork.util.math.Polar; +import mightypork.util.math.Calc.Deg; + + +public class MIPMouseWalk implements MapInteractionPlugin { + + @Override + public void onStepEnd(MapView wv, PlayerControl player) + { + if (InputSystem.isMouseButtonDown(0)) { + // walk by holding btn + onClick(wv, player, InputSystem.getMousePos()); + } + } + + + @Override + public void onClick(MapView wv, PlayerControl player, Vect mouse) + { + WorldPos plpos = player.getPos(); + WorldPos clicked = wv.toWorldPos(mouse); + + Polar p = Polar.fromCoord(clicked.x - plpos.x, clicked.y - plpos.y); + + int dir = Deg.round90(p.getAngleDeg()) / 90; + + switch (dir) { + case 0: + player.goEast(); + return; + + case 1: + player.goSouth(); + return; + + case 2: + player.goWest(); + return; + + case 3: + player.goNorth(); + return; + } + } + + + @Override + public void onKey(MapView wv, PlayerControl player, int key) + { + } + +} diff --git a/src/mightypork/rogue/screens/gamescreen/world/MapInteractionPlugin.java b/src/mightypork/rogue/screens/gamescreen/world/MapInteractionPlugin.java new file mode 100644 index 0000000..ef02e7e --- /dev/null +++ b/src/mightypork/rogue/screens/gamescreen/world/MapInteractionPlugin.java @@ -0,0 +1,18 @@ +package mightypork.rogue.screens.gamescreen.world; + + +import mightypork.rogue.world.PlayerControl; +import mightypork.util.constraints.vect.Vect; + + +public interface MapInteractionPlugin { + + void onStepEnd(MapView wv, PlayerControl player); + + + void onClick(MapView wv, PlayerControl player, Vect mouse); + + + void onKey(MapView wv, PlayerControl player, int key); + +} diff --git a/src/mightypork/rogue/screens/gamescreen/world/MapView.java b/src/mightypork/rogue/screens/gamescreen/world/MapView.java new file mode 100644 index 0000000..bf1b09d --- /dev/null +++ b/src/mightypork/rogue/screens/gamescreen/world/MapView.java @@ -0,0 +1,124 @@ +package mightypork.rogue.screens.gamescreen.world; + + +import java.util.HashSet; +import java.util.Set; + +import mightypork.gamecore.control.events.input.KeyEvent; +import mightypork.gamecore.control.events.input.KeyListener; +import mightypork.gamecore.control.events.input.MouseButtonEvent; +import mightypork.gamecore.control.events.input.MouseButtonListener; +import mightypork.gamecore.gui.components.InputComponent; +import mightypork.rogue.world.PlayerControl; +import mightypork.rogue.world.World; +import mightypork.rogue.world.WorldPos; +import mightypork.rogue.world.WorldRenderer; +import mightypork.rogue.world.entity.Entity; +import mightypork.rogue.world.entity.models.EntityMoveListener; +import mightypork.rogue.world.level.Level; +import mightypork.util.constraints.vect.Vect; + + +public class MapView extends InputComponent implements KeyListener, MouseButtonListener, EntityMoveListener { + + protected final WorldRenderer worldRenderer; + protected final World world; + private final PlayerControl pc; + + private final Set plugins = new HashSet<>(); + + + public MapView(World world) { + this.world = world; + this.worldRenderer = new WorldRenderer(world, this, 8, 6, 72); + pc = world.getPlayerControl(); + pc.addMoveListener(this); + } + + + @Override + protected void renderComponent() + { + worldRenderer.render(); + } + + + @Override + public void updateLayout() + { + worldRenderer.poll(); // update sizing + } + + + /** + * Get tile coord at a screen position + * + * @param pos position on screen (px) + * @return position on map (tiles) + */ + public WorldPos toWorldPos(Vect pos) + { + return worldRenderer.getClickedTile(pos); + } + + + @Override + public void onStepFinished(Entity entity, World world, Level level) + { + for (MapInteractionPlugin p : plugins) { + p.onStepEnd(this, pc); + } + } + + + @Override + public void onPathFinished(Entity entity, World world, Level level) + { + for (MapInteractionPlugin p : plugins) { + p.onStepEnd(this, pc); + } + } + + + @Override + public void onPathInterrupted(Entity entity, World world, Level level) + { + for (MapInteractionPlugin p : plugins) { + p.onStepEnd(this, pc); + } + } + + + @Override + public void receive(MouseButtonEvent event) + { + if (!event.isOver(this)) return; + + if (!event.isUp()) return; // only btn-release evt + + for (MapInteractionPlugin p : plugins) { + p.onClick(this, pc, event.getPos()); + } + + event.consume(); // only our clicks. + } + + + @Override + public void receive(KeyEvent event) + { + if (!event.isDown()) return; + + for (MapInteractionPlugin p : plugins) { + p.onKey(this, pc, event.getKey()); + } + + // don't consume key events, can be useful for others. + } + + + public void addPlugin(MapInteractionPlugin plugin) + { + plugins.add(plugin); + } +} diff --git a/src/mightypork/rogue/screens/main_menu/MenuLayer.java b/src/mightypork/rogue/screens/main_menu/MenuLayer.java index 3563536..3f23196 100644 --- a/src/mightypork/rogue/screens/main_menu/MenuLayer.java +++ b/src/mightypork/rogue/screens/main_menu/MenuLayer.java @@ -112,7 +112,7 @@ class MenuLayer extends ScreenLayer { @Override - public int getPriority() + public int getZIndex() { return 2; } diff --git a/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java b/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java index 99ccd34..4185fd9 100644 --- a/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java +++ b/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java @@ -81,7 +81,7 @@ public class LayerBouncyBoxes extends ScreenLayer { @Override - public int getPriority() + public int getZIndex() { return 0; } diff --git a/src/mightypork/rogue/screens/test_cat_sound/LayerColor.java b/src/mightypork/rogue/screens/test_cat_sound/LayerColor.java index e2cd1a7..22ed543 100644 --- a/src/mightypork/rogue/screens/test_cat_sound/LayerColor.java +++ b/src/mightypork/rogue/screens/test_cat_sound/LayerColor.java @@ -18,7 +18,7 @@ public class LayerColor extends ScreenLayer { @Override - public int getPriority() + public int getZIndex() { return Integer.MIN_VALUE; } diff --git a/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java b/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java index b609113..58eeba4 100644 --- a/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java +++ b/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java @@ -3,7 +3,8 @@ package mightypork.rogue.screens.test_cat_sound; import java.util.Random; -import mightypork.gamecore.control.events.MouseButtonEvent; +import mightypork.gamecore.control.events.input.MouseButtonEvent; +import mightypork.gamecore.control.events.input.MouseButtonListener; import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.components.painters.ImagePainter; import mightypork.gamecore.gui.components.painters.QuadPainter; @@ -21,7 +22,7 @@ import mightypork.util.math.Easing; import mightypork.util.math.color.Color; -public class LayerFlyingCat extends ScreenLayer implements MouseButtonEvent.Listener { +public class LayerFlyingCat extends ScreenLayer implements MouseButtonListener { private final NumAnimated size = new NumAnimated(300, Easing.SINE_BOTH); private final VectAnimated cat_position = VectAnimated.makeVar(Easing.ELASTIC_OUT); @@ -99,7 +100,7 @@ public class LayerFlyingCat extends ScreenLayer implements MouseButtonEvent.List @Override - public int getPriority() + public int getZIndex() { return 10; } diff --git a/src/mightypork/rogue/screens/test_render/LayerTestGradient.java b/src/mightypork/rogue/screens/test_render/LayerTestGradient.java index a5d1afa..38feb1e 100644 --- a/src/mightypork/rogue/screens/test_render/LayerTestGradient.java +++ b/src/mightypork/rogue/screens/test_render/LayerTestGradient.java @@ -33,7 +33,7 @@ public class LayerTestGradient extends ScreenLayer { @Override - public int getPriority() + public int getZIndex() { return 0; } diff --git a/src/mightypork/rogue/world/PlayerControl.java b/src/mightypork/rogue/world/PlayerControl.java index 0052c8c..4fa0784 100644 --- a/src/mightypork/rogue/world/PlayerControl.java +++ b/src/mightypork/rogue/world/PlayerControl.java @@ -2,6 +2,7 @@ package mightypork.rogue.world; import mightypork.rogue.world.entity.models.EntityMoveListener; +import mightypork.rogue.world.level.Level; public class PlayerControl { @@ -9,50 +10,55 @@ public class PlayerControl { private final World world; - public PlayerControl(World w) - { + public PlayerControl(World w) { this.world = w; } - public void walkNorth() + public void goNorth() { - world.playerEntity.addStep(PathStep.NORTH); + world.getPlayerEntity().addStep(PathStep.NORTH); } - public void walkSouth() + public void goSouth() { - world.playerEntity.addStep(PathStep.SOUTH); + world.getPlayerEntity().addStep(PathStep.SOUTH); } - public void walkEast() + public void goEast() { - world.playerEntity.addStep(PathStep.EAST); + world.getPlayerEntity().addStep(PathStep.EAST); } - public void walkWest() + public void goWest() { - world.playerEntity.addStep(PathStep.WEST); + world.getPlayerEntity().addStep(PathStep.WEST); } public void addMoveListener(EntityMoveListener eml) { - world.playerEntity.addMoveListener(eml); + world.getPlayerEntity().addMoveListener(eml); } - - + + public WorldPos getPos() { - return world.playerEntity.getPosition(); + return world.getPlayerEntity().getPosition(); } - - - public void walk(PathStep step) + + + public World getWorld() + { + return world; + } + + + public Level getLevel() { - world.playerEntity.addStep(step); + return world.getCurrentLevel(); } } diff --git a/src/mightypork/rogue/world/World.java b/src/mightypork/rogue/world/World.java index f467ec7..054a911 100644 --- a/src/mightypork/rogue/world/World.java +++ b/src/mightypork/rogue/world/World.java @@ -21,8 +21,8 @@ public class World implements IonBundled, Updateable { private final ArrayList levels = new ArrayList<>(); - final PlayerInfo player = new PlayerInfo(); - Entity playerEntity; + private final PlayerInfo playerInfo = new PlayerInfo(); + private Entity playerEntity; private final PlayerControl control = new PlayerControl(this); @@ -36,9 +36,9 @@ public class World implements IonBundled, Updateable { seed = in.get("seed", 0L); eid = in.get("next_eid", 0); in.loadSequence("levels", levels); - in.loadBundled("player", player); + in.loadBundled("player", playerInfo); - playerEntity = levels.get(player.getLevel()).getEntity(player.getEID()); + playerEntity = levels.get(playerInfo.getLevel()).getEntity(playerInfo.getEID()); } @@ -48,7 +48,7 @@ public class World implements IonBundled, Updateable { out.put("seed", seed); out.put("next_eid", eid); out.putSequence("levels", levels); - out.putBundled("player", player); + out.putBundled("player", playerInfo); } @@ -88,7 +88,7 @@ public class World implements IonBundled, Updateable { public void createPlayer(int x, int y, int level) { - if (player.isInitialized()) { + if (playerInfo.isInitialized()) { throw new RuntimeException("Player already created."); } @@ -97,8 +97,8 @@ public class World implements IonBundled, Updateable { playerEntity = Entities.PLAYER.createEntity(playerEid, new WorldPos(x, y)); - player.setLevel(level); - player.setEID(playerEid); + playerInfo.setLevel(level); + playerInfo.setEID(playerEid); levels.get(level).addEntity(playerEntity); } @@ -106,7 +106,7 @@ public class World implements IonBundled, Updateable { public Level getCurrentLevel() { - return levels.get(player.getLevel()); + return levels.get(playerInfo.getLevel()); } diff --git a/src/mightypork/rogue/world/WorldRenderer.java b/src/mightypork/rogue/world/WorldRenderer.java index 3b65d71..99d7282 100644 --- a/src/mightypork/rogue/world/WorldRenderer.java +++ b/src/mightypork/rogue/world/WorldRenderer.java @@ -14,6 +14,7 @@ import mightypork.util.constraints.rect.RectConst; import mightypork.util.constraints.rect.caching.RectCache; import mightypork.util.constraints.rect.proxy.RectProxy; import mightypork.util.constraints.vect.Vect; +import mightypork.util.constraints.vect.VectConst; import mightypork.util.constraints.vect.caching.VectCache; import mightypork.util.math.color.RGB; @@ -42,12 +43,14 @@ public class WorldRenderer extends RectProxy implements Pollable { private final Rect topShadow; private final Rect bottomShadow; + private TileRenderContext trc; + public WorldRenderer(World world, Rect viewport, int xTiles, int yTiles, int minTileSize) { super(viewport); this.world = world; - this.player = world.playerEntity; + this.player = world.getPlayerEntity(); tileSize = width().div(xTiles).min(height().div(yTiles)).max(minTileSize).cached(); @@ -62,11 +65,11 @@ public class WorldRenderer extends RectProxy implements Pollable { topShadow = topEdge().growDown(grY); bottomShadow = bottomEdge().growUp(grY); - setupMapRect(); + rebuildTiles(); } - private void setupMapRect() + private void rebuildTiles() { Level level = world.getCurrentLevel(); @@ -74,29 +77,30 @@ public class WorldRenderer extends RectProxy implements Pollable { activeLevel = level; mapRect = Rect.make(vpCenter, tileSize.mul(level.getWidth()), tileSize.mul(level.getHeight())).cached(); + + trc = new TileRenderContext(activeLevel, mapRect); } - private RectConst getCurrentDrawRect() + private int[] getOffset() { - WorldPos pos = player.getPosition(); final double playerX = pos.getVisualX(); final double playerY = pos.getVisualY(); double ts = tileSize.value(); - final RectConst drawRect = mapRect.move(-ts * playerX, -ts * playerY).freeze(); - - return drawRect; + return new int[]{(int) (-ts * playerX), (int) (-ts * playerY)}; } public void render() { - setupMapRect(); + int[] off = getOffset(); + System.out.println(trc.getRectForTile(10, 10)); - final TileRenderContext rc = new TileRenderContext(activeLevel, getCurrentDrawRect()); + Render.pushMatrix(); + Render.translate(off[0], off[1]); // tiles to render final WorldPos pos = player.getPosition(); @@ -117,9 +121,9 @@ public class WorldRenderer extends RectProxy implements Pollable { Render.enterBatchTexturedQuadMode(Res.getTexture("tiles16")); } - for (rc.y = y1; rc.y <= y2; rc.y++) { - for (rc.x = x1; rc.x <= x2; rc.x++) { - rc.renderTile(); + for (trc.y = y1; trc.y <= y2; trc.y++) { + for (trc.x = x1; trc.x <= x2; trc.x++) { + trc.renderTile(); } } @@ -129,9 +133,9 @@ public class WorldRenderer extends RectProxy implements Pollable { // === ITEMS ON TILES === - for (rc.y = y1; rc.y <= y2; rc.y++) { - for (rc.x = x1; rc.x <= x2; rc.x++) { - rc.renderItems(); + for (trc.y = y1; trc.y <= y2; trc.y++) { + for (trc.x = x1; trc.x <= x2; trc.x++) { + trc.renderItems(); } } @@ -146,9 +150,11 @@ public class WorldRenderer extends RectProxy implements Pollable { if (x < x1 - ts || x > x2 + ts) continue; if (y < y1 - ts || y > y2 + ts) continue; - e.render(rc); + e.render(trc); } + Render.popMatrix(); + // === OVERLAY SHADOW === Render.quadGradH(leftShadow, RGB.BLACK, RGB.NONE); @@ -161,9 +167,9 @@ public class WorldRenderer extends RectProxy implements Pollable { public WorldPos getClickedTile(Vect clickPos) { - RectConst drawRect = getCurrentDrawRect(); - Vect v = clickPos.sub(drawRect.origin()); - int ts = (int)tileSize.value(); + int[] off = getOffset(); + Vect v = clickPos.sub(mapRect.origin().add(off[0], off[1])); + int ts = (int) tileSize.value(); return new WorldPos(v.xi() / ts, v.yi() / ts); } @@ -176,6 +182,8 @@ public class WorldRenderer extends RectProxy implements Pollable { tileSize.poll(); mapRect.poll(); + + rebuildTiles(); } } diff --git a/src/mightypork/rogue/world/level/render/MapRenderContext.java b/src/mightypork/rogue/world/level/render/MapRenderContext.java index 573eaa6..55bac08 100644 --- a/src/mightypork/rogue/world/level/render/MapRenderContext.java +++ b/src/mightypork/rogue/world/level/render/MapRenderContext.java @@ -3,6 +3,7 @@ package mightypork.rogue.world.level.render; import mightypork.rogue.world.level.MapAccess; import mightypork.util.constraints.rect.Rect; +import mightypork.util.constraints.rect.RectConst; import mightypork.util.constraints.rect.builders.TiledRect; @@ -12,18 +13,33 @@ public abstract class MapRenderContext { protected final TiledRect tiler; private final Rect mapRect; + private RectConst tileRects[][]; - public MapRenderContext(MapAccess map, Rect drawArea) - { + + public MapRenderContext(MapAccess map, Rect drawArea) { this.map = map; this.tiler = drawArea.tiles(map.getWidth(), map.getHeight()); this.mapRect = drawArea; + + tileRects = new RectConst[map.getHeight()][map.getWidth()]; + + rebuildTileRects(); } + public void rebuildTileRects() + { + for(int y=0;y implements Digestable { private D last_digest; - private boolean caching_enabled; + private boolean caching_enabled = false; private boolean dirty = true; diff --git a/src/mightypork/util/control/eventbus/BusEvent.java b/src/mightypork/util/control/eventbus/BusEvent.java new file mode 100644 index 0000000..5ff884c --- /dev/null +++ b/src/mightypork/util/control/eventbus/BusEvent.java @@ -0,0 +1,115 @@ +package mightypork.util.control.eventbus; + + +import mightypork.util.control.eventbus.events.flags.DelayedEvent; +import mightypork.util.control.eventbus.events.flags.ImmediateEvent; +import mightypork.util.control.eventbus.events.flags.NonConsumableEvent; +import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent; +import mightypork.util.control.eventbus.events.flags.UnloggedEvent; + + +/** + *

+ * Event that can be handled by HANDLER, subscribing to the event bus. + *

+ *

+ * Can be annotated as {@link SingleReceiverEvent} to be delivered once only, + * and {@link DelayedEvent} or {@link ImmediateEvent} to specify default sending + * mode. When marked as {@link UnloggedEvent}, it will not appear in detailed + * bus logging (useful for very frequent events, such as UpdateEvent). + *

+ *

+ * Events annotated as {@link NonConsumableEvent} will throw an exception upon + * an attempt to consume them. + *

+ *

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

+ * + * @author MightyPork + * @param handler type + */ +public abstract class BusEvent { + + private boolean consumed; + private boolean served; + + + /** + * Ask handler to handle this message. + * + * @param handler handler instance + */ + protected abstract void handleBy(HANDLER handler); + + + /** + * Consume the event, so no other clients will receive it. + * + * @throws UnsupportedOperationException if the {@link NonConsumableEvent} + * annotation is present. + */ + public final void consume() + { + System.out.println("consume "+getClass()); + if (consumed) throw new IllegalStateException("Already consumed."); + + if (getClass().isAnnotationPresent(NonConsumableEvent.class)) { + throw new UnsupportedOperationException("Not consumable."); + } + + consumed = true; + } + + + /** + * Deliver to a handler using the handleBy method. + * + * @param handler handler instance + */ + final void deliverTo(HANDLER handler) + { + handleBy(handler); + + if (!served) { + if (getClass().isAnnotationPresent(SingleReceiverEvent.class)) { + consumed = true; + } + + served = true; + } + } + + + /** + * Check if the event is consumed. Consumed event is not served to other + * clients. + * + * @return true if consumed + */ + final boolean isConsumed() + { + return consumed; + } + + + /** + * @return true if the event was served to at least 1 client + */ + final boolean wasServed() + { + return served; + } + + + /** + * Clear "served" and "consumed" flags before dispatching. + */ + final void clearFlags() + { + served = false; + consumed = false; + } + +} diff --git a/src/mightypork/util/control/eventbus/EventBus.java b/src/mightypork/util/control/eventbus/EventBus.java index aee4b79..97a61b3 100644 --- a/src/mightypork/util/control/eventbus/EventBus.java +++ b/src/mightypork/util/control/eventbus/EventBus.java @@ -10,7 +10,6 @@ import java.util.concurrent.TimeUnit; import mightypork.util.control.Destroyable; import mightypork.util.control.eventbus.clients.DelegatingClient; -import mightypork.util.control.eventbus.events.Event; import mightypork.util.control.eventbus.events.flags.DelayedEvent; import mightypork.util.control.eventbus.events.flags.ImmediateEvent; import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent; @@ -32,10 +31,10 @@ final public class EventBus implements Destroyable { private class DelayQueueEntry implements Delayed { private final long due; - private final Event evt; + private final BusEvent evt; - public DelayQueueEntry(double seconds, Event event) + public DelayQueueEntry(double seconds, BusEvent event) { super(); this.due = System.currentTimeMillis() + (long) (seconds * 1000); @@ -57,7 +56,7 @@ final public class EventBus implements Destroyable { } - public Event getEvent() + public BusEvent getEvent() { return evt; } @@ -103,17 +102,17 @@ final public class EventBus implements Destroyable { static final String logMark = " "; - private static Class getEventListenerClass(Event event) + private static Class getEventListenerClass(BusEvent event) { // BEHOLD, MAGIC! - final Type[] interfaces = event.getClass().getGenericInterfaces(); - for (final Type interf : interfaces) { - if (interf instanceof ParameterizedType) { - if (((ParameterizedType) interf).getRawType() == Event.class) { - final Type[] types = ((ParameterizedType) interf).getActualTypeArguments(); - for (final Type genericType : types) { - return (Class) genericType; - } + + final Type evtc = event.getClass().getGenericSuperclass(); + + if (evtc instanceof ParameterizedType) { + if (((ParameterizedType) evtc).getRawType() == BusEvent.class) { + final Type[] types = ((ParameterizedType) evtc).getActualTypeArguments(); + for (final Type genericType : types) { + return (Class) genericType; } } } @@ -169,7 +168,7 @@ final public class EventBus implements Destroyable { * * @param event event */ - public void send(Event event) + public void send(BusEvent event) { assertLive(); @@ -193,7 +192,7 @@ final public class EventBus implements Destroyable { * * @param event event */ - public void sendQueued(Event event) + public void sendQueued(BusEvent event) { assertLive(); @@ -207,7 +206,7 @@ final public class EventBus implements Destroyable { * @param event event * @param delay delay before event is dispatched */ - public void sendDelayed(Event event, double delay) + public void sendDelayed(BusEvent event, double delay) { assertLive(); @@ -228,7 +227,7 @@ final public class EventBus implements Destroyable { * * @param event event */ - public void sendDirect(Event event) + public void sendDirect(BusEvent event) { assertLive(); @@ -238,7 +237,7 @@ final public class EventBus implements Destroyable { } - public void sendDirectToChildren(DelegatingClient delegatingClient, Event event) + public void sendDirectToChildren(DelegatingClient delegatingClient, BusEvent event) { assertLive(); @@ -282,7 +281,7 @@ final public class EventBus implements Destroyable { @SuppressWarnings("unchecked") - private boolean addChannelForEvent(Event event) + private boolean addChannelForEvent(BusEvent event) { try { if (detailedLogging) { @@ -298,7 +297,7 @@ final public class EventBus implements Destroyable { //channels.flush(); if (detailedLogging) { - Log.f2(" Created new channel: " + Log.str(event.getClass()) + " -> " + Log.str(listener)); + Log.f2(logMark + "Created new channel: " + Log.str(event.getClass()) + " -> " + Log.str(listener)); } return true; @@ -333,7 +332,7 @@ final public class EventBus implements Destroyable { * * @param event event */ - private synchronized void dispatch(Event event) + private synchronized void dispatch(BusEvent event) { assertLive(); @@ -349,12 +348,11 @@ final public class EventBus implements Destroyable { * @param clients clients * @param event event */ - private synchronized void doDispatch(Collection clients, Event event) + private synchronized void doDispatch(Collection clients, BusEvent event) { - boolean sent = false; boolean accepted = false; - final boolean singular = event.getClass().isAnnotationPresent(SingleReceiverEvent.class); + event.clearFlags(); for (int i = 0; i < 2; i++) { // two tries. @@ -362,10 +360,10 @@ final public class EventBus implements Destroyable { for (final EventChannel b : channels) { if (b.canBroadcast(event)) { accepted = true; - sent |= b.broadcast(event, clients); + b.broadcast(event, clients); } - if (sent && singular) break; + if (event.isConsumed()) break; } channels.setBuffering(false); @@ -375,11 +373,11 @@ final public class EventBus implements Destroyable { } if (!accepted) Log.e(logMark + "Not accepted by any channel: " + Log.str(event)); - if (!sent && shallLog(event)) Log.w(logMark + "Not delivered: " + Log.str(event)); + if (!event.wasServed() && shallLog(event)) Log.w(logMark + "Not delivered: " + Log.str(event)); } - private boolean shallLog(Event event) + private boolean shallLog(BusEvent event) { if (!detailedLogging) return false; if (event.getClass().isAnnotationPresent(UnloggedEvent.class)) return false; diff --git a/src/mightypork/util/control/eventbus/EventChannel.java b/src/mightypork/util/control/eventbus/EventChannel.java index 481d105..93589b0 100644 --- a/src/mightypork/util/control/eventbus/EventChannel.java +++ b/src/mightypork/util/control/eventbus/EventChannel.java @@ -6,7 +6,6 @@ import java.util.HashSet; import mightypork.util.control.eventbus.clients.DelegatingClient; import mightypork.util.control.eventbus.clients.ToggleableClient; -import mightypork.util.control.eventbus.events.Event; import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent; import mightypork.util.logging.Log; @@ -18,7 +17,7 @@ import mightypork.util.logging.Log; * @param event type * @param client (subscriber) type */ -class EventChannel, CLIENT> { +class EventChannel, CLIENT> { private final Class clientClass; private final Class eventClass; @@ -48,13 +47,12 @@ class EventChannel, CLIENT> { * * @param event a event to be sent * @param clients collection of clients - * @return true if event was sent */ - public boolean broadcast(Event event, Collection clients) + public void broadcast(BusEvent event, Collection clients) { - if (!canBroadcast(event)) return false; + if (!canBroadcast(event)) return; - return doBroadcast(eventClass.cast(event), clients, new HashSet<>()); + doBroadcast(eventClass.cast(event), clients, new HashSet<>()); } @@ -64,13 +62,9 @@ class EventChannel, CLIENT> { * @param event sent event * @param clients subscribing clients * @param processed clients already processed - * @return success */ - private boolean doBroadcast(final EVENT event, final Collection clients, final Collection processed) + private void doBroadcast(final EVENT event, final Collection clients, final Collection processed) { - boolean sent = false; - final boolean singular = event.getClass().isAnnotationPresent(SingleReceiverEvent.class); - for (final Object client : clients) { // exclude obvious non-clients @@ -90,10 +84,9 @@ class EventChannel, CLIENT> { if (!((ToggleableClient) client).isListening()) continue; } - sent |= sendTo(client, event); + sendTo(client, event); - // singular event ain't no whore, handled once only. - if (sent && singular) return true; + if (event.isConsumed()) return; // pass on to delegated clients if (client instanceof DelegatingClient) { @@ -102,14 +95,12 @@ class EventChannel, CLIENT> { final Collection children = ((DelegatingClient) client).getChildClients(); if (children != null && children.size() > 0) { - sent |= doBroadcast(event, children, processed); + doBroadcast(event, children, processed); } } } } - - return sent; } @@ -118,16 +109,13 @@ class EventChannel, CLIENT> { * * @param client target client * @param event event to send - * @return success */ @SuppressWarnings("unchecked") - private boolean sendTo(Object client, EVENT event) + private void sendTo(Object client, EVENT event) { - if (isClientOfType(client)) { - ((Event) event).handleBy((CLIENT) client); - return true; + if (isClientOfChannelType(client)) { + ((BusEvent) event).deliverTo((CLIENT) client); } - return false; } @@ -137,7 +125,7 @@ class EventChannel, CLIENT> { * @param event event object * @return can be broadcasted */ - public boolean canBroadcast(Event event) + public boolean canBroadcast(BusEvent event) { return event != null && eventClass.isInstance(event); } @@ -150,7 +138,7 @@ class EventChannel, CLIENT> { * @param clientClass client class * @return the broadcaster */ - public static , F_CLIENT> EventChannel create(Class eventClass, Class clientClass) + public static , F_CLIENT> EventChannel create(Class eventClass, Class clientClass) { return new EventChannel<>(eventClass, clientClass); } @@ -162,7 +150,7 @@ class EventChannel, CLIENT> { * @param client client * @return is of type */ - private boolean isClientOfType(Object client) + private boolean isClientOfChannelType(Object client) { return clientClass.isInstance(client); } @@ -176,7 +164,7 @@ class EventChannel, CLIENT> { */ public boolean isClientValid(Object client) { - return isClientOfType(client) || (client instanceof DelegatingClient); + return isClientOfChannelType(client) || (client instanceof DelegatingClient); } diff --git a/src/mightypork/util/control/eventbus/clients/BusNode.java b/src/mightypork/util/control/eventbus/clients/BusNode.java index fa90ba8..89fb66a 100644 --- a/src/mightypork/util/control/eventbus/clients/BusNode.java +++ b/src/mightypork/util/control/eventbus/clients/BusNode.java @@ -34,21 +34,21 @@ public abstract class BusNode implements BusAccess, ClientHub { @Override - public final Collection getChildClients() + public Collection getChildClients() { return clients; } @Override - public final boolean doesDelegate() + public boolean doesDelegate() { return delegating; } @Override - public final boolean isListening() + public boolean isListening() { return listening; } @@ -60,7 +60,7 @@ public abstract class BusNode implements BusAccess, ClientHub { * @param client */ @Override - public final void addChildClient(Object client) + public void addChildClient(Object client) { if (client instanceof RootBusNode) { throw new IllegalArgumentException("Cannot nest RootBusNode."); @@ -76,7 +76,7 @@ public abstract class BusNode implements BusAccess, ClientHub { * @param client subscriber to remove */ @Override - public final void removeChildClient(Object client) + public void removeChildClient(Object client) { if (client != null) { clients.remove(client); @@ -89,7 +89,7 @@ public abstract class BusNode implements BusAccess, ClientHub { * * @param listening receive events */ - public final void setListening(boolean listening) + public void setListening(boolean listening) { this.listening = listening; } @@ -100,14 +100,14 @@ public abstract class BusNode implements BusAccess, ClientHub { * * @param delegating */ - public final void setDelegating(boolean delegating) + public void setDelegating(boolean delegating) { this.delegating = delegating; } @Override - public final EventBus getEventBus() + public EventBus getEventBus() { return busAccess.getEventBus(); } diff --git a/src/mightypork/util/control/eventbus/events/Event.java b/src/mightypork/util/control/eventbus/events/Event.java deleted file mode 100644 index 7a4780a..0000000 --- a/src/mightypork/util/control/eventbus/events/Event.java +++ /dev/null @@ -1,36 +0,0 @@ -package mightypork.util.control.eventbus.events; - - -import mightypork.util.control.eventbus.events.flags.DelayedEvent; -import mightypork.util.control.eventbus.events.flags.ImmediateEvent; -import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent; -import mightypork.util.control.eventbus.events.flags.UnloggedEvent; - - -/** - *

- * Something that can be handled by HANDLER, subscribing to the event bus. - *

- *

- * Can be annotated as {@link SingleReceiverEvent} to be delivered once only, - * and {@link DelayedEvent} or {@link ImmediateEvent} to specify default sending - * mode. When marked as {@link UnloggedEvent}, it will not appear in detailed - * bus logging (useful for very frequent events, such as UpdateEvent). - *

- *

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

- * - * @author MightyPork - * @param handler type - */ -public interface Event { - - /** - * Ask handler to handle this message. - * - * @param handler handler instance - */ - public void handleBy(HANDLER handler); -} diff --git a/src/mightypork/util/control/eventbus/events/flags/NonConsumableEvent.java b/src/mightypork/util/control/eventbus/events/flags/NonConsumableEvent.java new file mode 100644 index 0000000..e39f949 --- /dev/null +++ b/src/mightypork/util/control/eventbus/events/flags/NonConsumableEvent.java @@ -0,0 +1,20 @@ +package mightypork.util.control.eventbus.events.flags; + +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; + + +/** + * Event that cannot be consumed + * + * @author MightyPork + */ +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Target(ElementType.TYPE) +public @interface NonConsumableEvent { + +}