From acc8dffad7bbcc103a5cf3f513b25d5d8659f57f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Wed, 2 Apr 2014 00:42:11 +0200 Subject: [PATCH] Cleaned up bus & systems; Finished constraint system. Layered screen. --- .classpath | 12 +- src/mightypork/rogue/App.java | 39 +- src/mightypork/rogue/AppAccess.java | 2 +- src/mightypork/rogue/AppAdapter.java | 2 +- src/mightypork/rogue/Config.java | 2 +- src/mightypork/rogue/bus/ChildClient.java | 100 +++++ .../rogue/bus/DelegatingBusClient.java | 162 ------- src/mightypork/rogue/bus/SimpleBusClient.java | 23 - src/mightypork/rogue/bus/Subsystem.java | 42 ++ src/mightypork/rogue/bus/UpdateReceiver.java | 26 -- .../rogue/bus/events/KeyboardEvent.java | 2 +- .../rogue/bus/events/MouseButtonEvent.java | 2 +- .../rogue/bus/events/MouseMotionEvent.java | 2 +- .../rogue/bus/events/ScreenChangeEvent.java | 2 +- .../rogue/bus/events/UpdateEvent.java | 33 -- .../rogue/display/DisplaySystem.java | 19 +- .../rogue/display/LayeredScreen.java | 47 ++- src/mightypork/rogue/display/Screen.java | 139 +++--- src/mightypork/rogue/display/ScreenLayer.java | 58 +++ .../display/constraints/BaseConstraint.java | 58 +++ .../rogue/display/constraints/Constraint.java | 59 --- .../constraints/ConstraintFactory.java | 394 ++++++++++++++++++ .../display/constraints/ElementHolder.java | 95 +++++ .../display/constraints/NumConstraint.java | 18 + .../display/constraints/RectConstraint.java | 22 + .../{Bounding.java => RenderContext.java} | 4 +- .../rogue/display/constraints/Renderable.java | 12 + .../display/constraints/WithContext.java | 12 + .../rogue/display/rendering/Renderable.java | 8 - .../rogue/display/rendering/ScreenLayer.java | 84 ---- .../{ => screens}/ScreenTestAnimations.java | 73 ++-- .../screens/screenBouncy/BouncyBox.java | 87 ++++ .../screenBouncy/LayerBouncyBoxes.java | 64 +++ .../screenBouncy/TestLayeredScreen.java | 70 ++++ src/mightypork/rogue/input/InputSystem.java | 20 +- src/mightypork/rogue/sounds/AudioX.java | 2 +- src/mightypork/rogue/sounds/LoopPlayer.java | 6 +- src/mightypork/rogue/sounds/SoundSystem.java | 16 +- .../rogue/testing/TestConstraints.java | 84 ---- src/mightypork/rogue/testing/TestMsgbus.java | 219 ---------- .../RenderUtils.java => textures/Render.java} | 116 +++++- .../rogue/textures/TextureManager.java | 76 ---- src/mightypork/rogue/textures/Textures.java | 40 -- src/mightypork/rogue/textures/Tx.java | 30 -- .../{patterns => control}/Destroyable.java | 2 +- .../bus}/Handleable.java | 2 +- .../bus}/MessageBus.java | 2 +- .../bus}/MessageChannel.java | 8 +- .../bus}/clients/DelegatingClient.java | 2 +- .../bus}/clients/ToggleableClient.java | 4 +- .../{time => control/timing}/FpsMeter.java | 2 +- .../{time => control/timing}/Pauseable.java | 2 +- .../{time => control/timing}/TimerDelta.java | 2 +- .../timing/TimerFps.java} | 6 +- .../utils/control/timing/UpdateEvent.java | 22 + .../{time => control/timing}/Updateable.java | 2 +- .../timing}/animation/AnimDouble.java | 6 +- .../timing}/animation/AnimDoubleDeg.java | 2 +- .../timing}/animation/AnimDoubleRad.java | 2 +- .../utils/math/coord/CoordAnimated.java | 2 +- src/mightypork/utils/math/coord/Rect.java | 132 +++--- src/mightypork/utils/math/easing/Easing.java | 20 +- 62 files changed, 1443 insertions(+), 1160 deletions(-) create mode 100644 src/mightypork/rogue/bus/ChildClient.java delete mode 100644 src/mightypork/rogue/bus/DelegatingBusClient.java delete mode 100644 src/mightypork/rogue/bus/SimpleBusClient.java create mode 100644 src/mightypork/rogue/bus/Subsystem.java delete mode 100644 src/mightypork/rogue/bus/UpdateReceiver.java delete mode 100644 src/mightypork/rogue/bus/events/UpdateEvent.java create mode 100644 src/mightypork/rogue/display/ScreenLayer.java create mode 100644 src/mightypork/rogue/display/constraints/BaseConstraint.java delete mode 100644 src/mightypork/rogue/display/constraints/Constraint.java create mode 100644 src/mightypork/rogue/display/constraints/ConstraintFactory.java create mode 100644 src/mightypork/rogue/display/constraints/ElementHolder.java create mode 100644 src/mightypork/rogue/display/constraints/NumConstraint.java create mode 100644 src/mightypork/rogue/display/constraints/RectConstraint.java rename src/mightypork/rogue/display/constraints/{Bounding.java => RenderContext.java} (67%) create mode 100644 src/mightypork/rogue/display/constraints/Renderable.java create mode 100644 src/mightypork/rogue/display/constraints/WithContext.java delete mode 100644 src/mightypork/rogue/display/rendering/Renderable.java delete mode 100644 src/mightypork/rogue/display/rendering/ScreenLayer.java rename src/mightypork/rogue/display/{ => screens}/ScreenTestAnimations.java (85%) create mode 100644 src/mightypork/rogue/display/screens/screenBouncy/BouncyBox.java create mode 100644 src/mightypork/rogue/display/screens/screenBouncy/LayerBouncyBoxes.java create mode 100644 src/mightypork/rogue/display/screens/screenBouncy/TestLayeredScreen.java delete mode 100644 src/mightypork/rogue/testing/TestConstraints.java delete mode 100644 src/mightypork/rogue/testing/TestMsgbus.java rename src/mightypork/rogue/{util/RenderUtils.java => textures/Render.java} (90%) delete mode 100644 src/mightypork/rogue/textures/TextureManager.java delete mode 100644 src/mightypork/rogue/textures/Textures.java delete mode 100644 src/mightypork/rogue/textures/Tx.java rename src/mightypork/utils/{patterns => control}/Destroyable.java (83%) rename src/mightypork/utils/{patterns/subscription => control/bus}/Handleable.java (85%) rename src/mightypork/utils/{patterns/subscription => control/bus}/MessageBus.java (98%) rename src/mightypork/utils/{patterns/subscription => control/bus}/MessageChannel.java (93%) rename src/mightypork/utils/{patterns/subscription => control/bus}/clients/DelegatingClient.java (86%) rename src/mightypork/utils/{patterns/subscription => control/bus}/clients/ToggleableClient.java (68%) rename src/mightypork/utils/{time => control/timing}/FpsMeter.java (96%) rename src/mightypork/utils/{time => control/timing}/Pauseable.java (83%) rename src/mightypork/utils/{time => control/timing}/TimerDelta.java (94%) rename src/mightypork/utils/{time/TimerInterpolating.java => control/timing/TimerFps.java} (94%) create mode 100644 src/mightypork/utils/control/timing/UpdateEvent.java rename src/mightypork/utils/{time => control/timing}/Updateable.java (86%) rename src/mightypork/utils/{time => control/timing}/animation/AnimDouble.java (96%) rename src/mightypork/utils/{time => control/timing}/animation/AnimDoubleDeg.java (94%) rename src/mightypork/utils/{time => control/timing}/animation/AnimDoubleRad.java (94%) diff --git a/.classpath b/.classpath index 91e7afc..a3b32fd 100644 --- a/.classpath +++ b/.classpath @@ -2,32 +2,32 @@ - + - + - + - + - + - + diff --git a/src/mightypork/rogue/App.java b/src/mightypork/rogue/App.java index 00bcfed..aad4add 100644 --- a/src/mightypork/rogue/App.java +++ b/src/mightypork/rogue/App.java @@ -7,20 +7,21 @@ import java.nio.channels.FileLock; import javax.swing.JOptionPane; -import mightypork.rogue.bus.events.UpdateEvent; import mightypork.rogue.display.DisplaySystem; import mightypork.rogue.display.Screen; -import mightypork.rogue.display.ScreenTestAnimations; +import mightypork.rogue.display.screens.screenBouncy.TestLayeredScreen; import mightypork.rogue.input.InputSystem; import mightypork.rogue.input.KeyStroke; import mightypork.rogue.sounds.SoundSystem; import mightypork.rogue.tasks.TaskTakeScreenshot; import mightypork.rogue.util.Utils; +import mightypork.utils.control.Destroyable; +import mightypork.utils.control.bus.MessageBus; +import mightypork.utils.control.timing.TimerDelta; +import mightypork.utils.control.timing.UpdateEvent; +import mightypork.utils.control.timing.Updateable; import mightypork.utils.logging.Log; import mightypork.utils.logging.LogInstance; -import mightypork.utils.patterns.Destroyable; -import mightypork.utils.patterns.subscription.MessageBus; -import mightypork.utils.time.TimerDelta; import org.lwjgl.input.Keyboard; @@ -46,12 +47,16 @@ public class App implements Destroyable, AppAccess { /** Flag that screenshot is scheduled to be taken next loop */ private boolean scheduledScreenshot = false; + /** Log instance; accessible as static via Log. */ + private LogInstance log; + /** * @param args */ public static void main(String[] args) { + Config.init(); Thread.setDefaultUncaughtExceptionHandler(new CrashHandler()); @@ -170,7 +175,7 @@ public class App implements Destroyable, AppAccess { events = new MessageBus(); events.subscribe(this); - events.createChannel(UpdateEvent.class, UpdateEvent.Listener.class); + events.createChannel(UpdateEvent.class, Updateable.class); } @@ -180,6 +185,7 @@ public class App implements Destroyable, AppAccess { private void initSound() { sounds = new SoundSystem(this); + sounds.setMasterVolume(1); } @@ -229,6 +235,7 @@ public class App implements Destroyable, AppAccess { private void initDisplay() { display = new DisplaySystem(this); + display.createMainWindow(Const.WINDOW_W, Const.WINDOW_H, true, Config.START_IN_FS, Const.TITLEBAR); display.setTargetFps(Const.FPS_RENDER); } @@ -239,16 +246,18 @@ public class App implements Destroyable, AppAccess { */ private void initLogger() { - LogInstance li = Log.create("runtime", Paths.LOGS, 10); - li.enable(Config.LOGGING_ENABLED); - li.enableSysout(Config.LOG_TO_STDOUT); + log = Log.create("runtime", Paths.LOGS, 10); + log.enable(Config.LOGGING_ENABLED); + log.enableSysout(Config.LOG_TO_STDOUT); } private void start() { initialize(); + mainLoop(); + shutdown(); } @@ -256,9 +265,13 @@ public class App implements Destroyable, AppAccess { private TimerDelta timerRender; + /** + * App main loop + */ private void mainLoop() { - screen = new ScreenTestAnimations(this); + screen = new TestLayeredScreen(this); + screen.setActive(true); timerRender = new TimerDelta(); @@ -281,17 +294,13 @@ public class App implements Destroyable, AppAccess { /** * Do take a screenshot */ - public void takeScreenshot() + private void takeScreenshot() { sounds.getEffect("gui.shutter").play(1); Utils.runAsThread(new TaskTakeScreenshot(display)); } - // - // static accessors - // - /** * @return sound system of the running instance */ diff --git a/src/mightypork/rogue/AppAccess.java b/src/mightypork/rogue/AppAccess.java index 925eee4..b56026f 100644 --- a/src/mightypork/rogue/AppAccess.java +++ b/src/mightypork/rogue/AppAccess.java @@ -4,7 +4,7 @@ package mightypork.rogue; import mightypork.rogue.display.DisplaySystem; import mightypork.rogue.input.InputSystem; import mightypork.rogue.sounds.SoundSystem; -import mightypork.utils.patterns.subscription.MessageBus; +import mightypork.utils.control.bus.MessageBus; /** diff --git a/src/mightypork/rogue/AppAdapter.java b/src/mightypork/rogue/AppAdapter.java index e7263b2..467dbe4 100644 --- a/src/mightypork/rogue/AppAdapter.java +++ b/src/mightypork/rogue/AppAdapter.java @@ -4,7 +4,7 @@ package mightypork.rogue; import mightypork.rogue.display.DisplaySystem; import mightypork.rogue.input.InputSystem; import mightypork.rogue.sounds.SoundSystem; -import mightypork.utils.patterns.subscription.MessageBus; +import mightypork.utils.control.bus.MessageBus; /** diff --git a/src/mightypork/rogue/Config.java b/src/mightypork/rogue/Config.java index 08dc87c..1555b78 100644 --- a/src/mightypork/rogue/Config.java +++ b/src/mightypork/rogue/Config.java @@ -41,7 +41,7 @@ public class Config { mgr.cfgSeparateSections(true); mgr.putInteger(PK_LAST_RUN_VERSION, def_LAST_RUN_VERSION); - mgr.putBoolean(PK_START_IN_FS, def_START_IN_FS); + mgr.putBoolean(PK_START_IN_FS, def_START_IN_FS, "Go to fullscreen on startup."); load(); // load what has been "put" } diff --git a/src/mightypork/rogue/bus/ChildClient.java b/src/mightypork/rogue/bus/ChildClient.java new file mode 100644 index 0000000..98071b6 --- /dev/null +++ b/src/mightypork/rogue/bus/ChildClient.java @@ -0,0 +1,100 @@ +package mightypork.rogue.bus; + + +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.Set; + +import mightypork.rogue.AppAccess; +import mightypork.rogue.AppAdapter; +import mightypork.utils.control.bus.MessageBus; +import mightypork.utils.control.bus.clients.DelegatingClient; +import mightypork.utils.control.bus.clients.ToggleableClient; + + +/** + * Client that can be attached to the {@link MessageBus}, or added as a child + * client to another {@link DelegatingClient} + * + * @author MightyPork + */ +public class ChildClient extends AppAdapter implements DelegatingClient, ToggleableClient { + + public ChildClient(AppAccess app) { + super(app); + } + + private Set clients = new LinkedHashSet(); + private boolean listening = true; + private boolean delegating = true; + + + @Override + public final Collection getChildClients() + { + return clients; + } + + + @Override + public final boolean doesDelegate() + { + return delegating; + } + + + @Override + public boolean isListening() + { + return listening; + } + + + /** + * Add a child subscriber to the {@link MessageBus}.
+ * + * @param client + */ + public final void addChildClient(Object client) + { + if (client != null) { + clients.add(client); + } + } + + + /** + * Remove a child subscriber + * + * @param client subscriber to remove + */ + public final void removeChildClient(Object client) + { + if (client != null) { + clients.remove(client); + } + } + + + /** + * Set whether events should be received. + * + * @param listening receive events + */ + public final void setListening(boolean listening) + { + this.listening = listening; + } + + + /** + * Set whether events should be passed on to child nodes + * + * @param delegating + */ + public final void setDelegating(boolean delegating) + { + this.delegating = delegating; + } + +} diff --git a/src/mightypork/rogue/bus/DelegatingBusClient.java b/src/mightypork/rogue/bus/DelegatingBusClient.java deleted file mode 100644 index 07b8772..0000000 --- a/src/mightypork/rogue/bus/DelegatingBusClient.java +++ /dev/null @@ -1,162 +0,0 @@ -package mightypork.rogue.bus; - - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import mightypork.rogue.AppAccess; -import mightypork.rogue.AppAdapter; -import mightypork.rogue.bus.events.UpdateEvent; -import mightypork.utils.logging.Log; -import mightypork.utils.patterns.Destroyable; -import mightypork.utils.patterns.subscription.MessageBus; -import mightypork.utils.patterns.subscription.clients.DelegatingClient; -import mightypork.utils.patterns.subscription.clients.ToggleableClient; -import mightypork.utils.time.Updateable; - - -/** - * App event bus client, to be used for subsystems, screens and anything that - * needs access to the eventbus - * - * @author MightyPork - */ -public abstract class DelegatingBusClient extends AppAdapter implements DelegatingClient, ToggleableClient, Destroyable, Updateable, UpdateEvent.Listener { - - /** Subsystem children subscribing to MessageBus */ - private Set childSubscribers = new HashSet(); - - private boolean wantUpdates = true; - private boolean eventsEnabled = true; - - - public DelegatingBusClient(AppAccess app, boolean updates) { - super(app); - - bus().subscribe(this); - - enableUpdates(updates); - - init(); - } - - - /** - * Add a child subscriber to the {@link MessageBus}.
- * - * @param client - * @return true on success - */ - public final boolean addChildSubscriber(Object client) - { - if (client == null) return false; - - childSubscribers.add(client); - - return true; - } - - - /** - * Remove a child subscriber - * - * @param client subscriber to remove - */ - public final void removeChildSubscriber(Object client) - { - if (client == null) return; - - childSubscribers.remove(client); - } - - - @Override - public final Collection getChildClients() - { - return childSubscribers; - } - - - @Override - public final boolean doesDelegate() - { - return doesSubscribe(); - } - - - /** - * Set whether to receive {@link UpdateEvent}s (delta timing, one each - * frame).
- * - * @param enable - */ - public final void enableUpdates(boolean enable) - { - wantUpdates = enable; - } - - - @Override - public final boolean doesSubscribe() - { - return eventsEnabled; - } - - - /** - * Set whether events should be received. - * - * @param enable - */ - public final void enableEvents(boolean enable) - { - this.eventsEnabled = enable; - } - - - @Override - public final void receive(UpdateEvent event) - { - if (wantUpdates) update(event.getDeltaTime()); - } - - - @Override - public final void destroy() - { - deinit(); - - enableUpdates(false); - - bus().unsubscribe(this); - } - - - @Override - public void update(double delta) - { - Log.w("Client " + getClass().getSimpleName() + " receives updates, but does not override the update() method."); - } - - - /** - * Initialize the subsystem
- * (called during construction) - */ - protected void init() - { - // no impl - } - - - /** - * Deinitialize the subsystem
- * (called during destruction) - */ - protected void deinit() - { - // no impl - } - -} diff --git a/src/mightypork/rogue/bus/SimpleBusClient.java b/src/mightypork/rogue/bus/SimpleBusClient.java deleted file mode 100644 index 00d1795..0000000 --- a/src/mightypork/rogue/bus/SimpleBusClient.java +++ /dev/null @@ -1,23 +0,0 @@ -package mightypork.rogue.bus; - - -import mightypork.rogue.AppAccess; -import mightypork.rogue.AppAdapter; - - -/** - * Simplest event bus client with app access - * - * @author MightyPork - */ -public class SimpleBusClient extends AppAdapter { - - /** - * @param app app access - */ - public SimpleBusClient(AppAccess app) { - super(app); - - bus().subscribe(this); - } -} diff --git a/src/mightypork/rogue/bus/Subsystem.java b/src/mightypork/rogue/bus/Subsystem.java new file mode 100644 index 0000000..330ea4f --- /dev/null +++ b/src/mightypork/rogue/bus/Subsystem.java @@ -0,0 +1,42 @@ +package mightypork.rogue.bus; + + +import mightypork.rogue.AppAccess; +import mightypork.utils.control.Destroyable; +import mightypork.utils.control.bus.clients.DelegatingClient; +import mightypork.utils.control.bus.clients.ToggleableClient; + + +/** + * App event bus client, to be used for subsystems, screens and anything that + * needs access to the eventbus + * + * @author MightyPork + */ +public abstract class Subsystem extends ChildClient implements DelegatingClient, ToggleableClient, Destroyable { + + public Subsystem(AppAccess app) { + super(app); + + bus().subscribe(this); + } + + + @Override + public final void destroy() + { + deinit(); + + setListening(false); + + bus().unsubscribe(this); + } + + + /** + * Deinitialize the subsystem
+ * (called during destruction) + */ + protected abstract void deinit(); + +} diff --git a/src/mightypork/rogue/bus/UpdateReceiver.java b/src/mightypork/rogue/bus/UpdateReceiver.java deleted file mode 100644 index ae5a129..0000000 --- a/src/mightypork/rogue/bus/UpdateReceiver.java +++ /dev/null @@ -1,26 +0,0 @@ -package mightypork.rogue.bus; - - -import mightypork.rogue.AppAccess; -import mightypork.rogue.bus.events.UpdateEvent; -import mightypork.utils.time.Updateable; - - -public abstract class UpdateReceiver extends SimpleBusClient implements UpdateEvent.Listener, Updateable { - - public UpdateReceiver(AppAccess app) { - super(app); - } - - - @Override - public void receive(UpdateEvent event) - { - update(event.getDeltaTime()); - } - - - @Override - public abstract void update(double delta); - -} diff --git a/src/mightypork/rogue/bus/events/KeyboardEvent.java b/src/mightypork/rogue/bus/events/KeyboardEvent.java index fb34203..8a6bdba 100644 --- a/src/mightypork/rogue/bus/events/KeyboardEvent.java +++ b/src/mightypork/rogue/bus/events/KeyboardEvent.java @@ -1,7 +1,7 @@ package mightypork.rogue.bus.events; -import mightypork.utils.patterns.subscription.Handleable; +import mightypork.utils.control.bus.Handleable; import org.lwjgl.input.Keyboard; diff --git a/src/mightypork/rogue/bus/events/MouseButtonEvent.java b/src/mightypork/rogue/bus/events/MouseButtonEvent.java index 2639050..5e1f42a 100644 --- a/src/mightypork/rogue/bus/events/MouseButtonEvent.java +++ b/src/mightypork/rogue/bus/events/MouseButtonEvent.java @@ -1,8 +1,8 @@ package mightypork.rogue.bus.events; +import mightypork.utils.control.bus.Handleable; import mightypork.utils.math.coord.Coord; -import mightypork.utils.patterns.subscription.Handleable; /** diff --git a/src/mightypork/rogue/bus/events/MouseMotionEvent.java b/src/mightypork/rogue/bus/events/MouseMotionEvent.java index b440aeb..a8f447d 100644 --- a/src/mightypork/rogue/bus/events/MouseMotionEvent.java +++ b/src/mightypork/rogue/bus/events/MouseMotionEvent.java @@ -1,8 +1,8 @@ package mightypork.rogue.bus.events; +import mightypork.utils.control.bus.Handleable; import mightypork.utils.math.coord.Coord; -import mightypork.utils.patterns.subscription.Handleable; public class MouseMotionEvent implements Handleable { diff --git a/src/mightypork/rogue/bus/events/ScreenChangeEvent.java b/src/mightypork/rogue/bus/events/ScreenChangeEvent.java index 746ecff..ad9e714 100644 --- a/src/mightypork/rogue/bus/events/ScreenChangeEvent.java +++ b/src/mightypork/rogue/bus/events/ScreenChangeEvent.java @@ -1,8 +1,8 @@ package mightypork.rogue.bus.events; +import mightypork.utils.control.bus.Handleable; import mightypork.utils.math.coord.Coord; -import mightypork.utils.patterns.subscription.Handleable; public class ScreenChangeEvent implements Handleable { diff --git a/src/mightypork/rogue/bus/events/UpdateEvent.java b/src/mightypork/rogue/bus/events/UpdateEvent.java deleted file mode 100644 index 583dc2a..0000000 --- a/src/mightypork/rogue/bus/events/UpdateEvent.java +++ /dev/null @@ -1,33 +0,0 @@ -package mightypork.rogue.bus.events; - - -import mightypork.utils.patterns.subscription.Handleable; - - -public class UpdateEvent implements Handleable { - - private final double deltaTime; - - - public UpdateEvent(double deltaTime) { - this.deltaTime = deltaTime; - } - - - public double getDeltaTime() - { - return deltaTime; - } - - - @Override - public void handleBy(Listener handler) - { - handler.receive(this); - } - - public interface Listener { - - public void receive(UpdateEvent event); - } -} diff --git a/src/mightypork/rogue/display/DisplaySystem.java b/src/mightypork/rogue/display/DisplaySystem.java index 4702801..c01fea4 100644 --- a/src/mightypork/rogue/display/DisplaySystem.java +++ b/src/mightypork/rogue/display/DisplaySystem.java @@ -7,9 +7,9 @@ import java.awt.image.BufferedImage; import java.nio.ByteBuffer; import mightypork.rogue.AppAccess; -import mightypork.rogue.bus.DelegatingBusClient; +import mightypork.rogue.bus.Subsystem; import mightypork.rogue.bus.events.ScreenChangeEvent; -import mightypork.rogue.display.constraints.Bounding; +import mightypork.rogue.display.constraints.RenderContext; import mightypork.utils.logging.Log; import mightypork.utils.math.coord.Coord; import mightypork.utils.math.coord.Rect; @@ -20,27 +20,21 @@ import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; -public class DisplaySystem extends DelegatingBusClient implements Bounding { +public class DisplaySystem extends Subsystem implements RenderContext { private DisplayMode windowDisplayMode; private int targetFps; public DisplaySystem(AppAccess app) { - super(app, true); - enableUpdates(false); - } - - - @Override - protected void init() - { + super(app); + initChannels(); } @Override - public void deinit() + protected void deinit() { Display.destroy(); } @@ -178,6 +172,7 @@ public class DisplaySystem extends DelegatingBusClient implements Bounding { */ public void beginFrame() { + // handle resize if (Display.wasResized()) { bus().broadcast(new ScreenChangeEvent(false, Display.isFullscreen(), getSize())); } diff --git a/src/mightypork/rogue/display/LayeredScreen.java b/src/mightypork/rogue/display/LayeredScreen.java index 1f1bb56..20af9e8 100644 --- a/src/mightypork/rogue/display/LayeredScreen.java +++ b/src/mightypork/rogue/display/LayeredScreen.java @@ -1,16 +1,15 @@ package mightypork.rogue.display; -import java.util.ArrayList; -import java.util.List; +import java.util.LinkedList; import mightypork.rogue.AppAccess; -import mightypork.rogue.display.rendering.ScreenLayer; +import mightypork.utils.control.timing.Updateable; public abstract class LayeredScreen extends Screen { - private List layers = new ArrayList(); + private final LinkedList layers = new LinkedList(); public LayeredScreen(AppAccess app) { @@ -18,10 +17,6 @@ public abstract class LayeredScreen extends Screen { } - @Override - protected abstract void initScreen(); - - @Override protected abstract void deinitScreen(); @@ -35,33 +30,43 @@ public abstract class LayeredScreen extends Screen { @Override - protected void renderScreen() + protected final void renderScreen() { - // in reverse order (topmost added last) - for (int i = layers.size() - 1; i >= 0; i--) { - layers.get(i).render(); + for (ScreenLayer layer : layers) { + layer.render(); } } + /** + * Update screen. Layers should implement {@link Updateable} to receive + * updates directly from bus. + */ @Override - protected void updateScreen(double delta) - { - // no impl - } + protected abstract void updateScreen(double delta); - protected void addLayer(ScreenLayer layer) + /** + * Add a layer to the screen. + * + * @param layer + */ + protected final void addLayer(ScreenLayer layer) { - this.layers.add(layer); - addChildSubscriber(layer); + this.layers.add(layer); // will be rendered from last to first + addChildClient(layer); // connect to bus } - protected void removeLayer(ScreenLayer layer) + /** + * Remove a layer + * + * @param layer + */ + protected final void removeLayer(ScreenLayer layer) { this.layers.remove(layer); - addChildSubscriber(layer); + removeChildClient(layer); } } diff --git a/src/mightypork/rogue/display/Screen.java b/src/mightypork/rogue/display/Screen.java index 70a8e29..09f1c86 100644 --- a/src/mightypork/rogue/display/Screen.java +++ b/src/mightypork/rogue/display/Screen.java @@ -2,14 +2,14 @@ package mightypork.rogue.display; import static org.lwjgl.opengl.GL11.*; - import mightypork.rogue.AppAccess; -import mightypork.rogue.bus.DelegatingBusClient; +import mightypork.rogue.bus.Subsystem; import mightypork.rogue.bus.events.ScreenChangeEvent; -import mightypork.rogue.display.constraints.Bounding; +import mightypork.rogue.display.constraints.RenderContext; import mightypork.rogue.input.KeyBinder; import mightypork.rogue.input.KeyBindingPool; import mightypork.rogue.input.KeyStroke; +import mightypork.utils.control.timing.Updateable; import mightypork.utils.math.coord.Coord; import mightypork.utils.math.coord.Rect; @@ -21,18 +21,22 @@ import mightypork.utils.math.coord.Rect; * * @author MightyPork */ -public abstract class Screen extends DelegatingBusClient implements KeyBinder, Bounding, ScreenChangeEvent.Listener { +public abstract class Screen extends Subsystem implements Updateable, KeyBinder, RenderContext, ScreenChangeEvent.Listener { - private KeyBindingPool keybindings; + private final KeyBindingPool keybindings = new KeyBindingPool(); private boolean active; + private boolean inited = false; + public Screen(AppAccess app) { - super(app, true); + super(app); // disable events initially - enableEvents(false); + setListening(false); + + addChildClient(keybindings); } @@ -50,6 +54,13 @@ public abstract class Screen extends DelegatingBusClient implements KeyBinder, B } + @Override + protected final void deinit() + { + deinitScreen(); + } + + /** * Prepare for being shown * @@ -64,83 +75,20 @@ public abstract class Screen extends DelegatingBusClient implements KeyBinder, B onSizeChanged(getRect().getSize()); onScreenEnter(); - // subscribe to event bus - enableEvents(true); + // enable events + setListening(true); } else { onScreenLeave(); active = false; - // unsusbcribe from event bus - enableEvents(false); + // disable events + setListening(false); } } - private void setupGraphics() - { - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - glDisable(GL_LIGHTING); - - glClearDepth(1f); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LEQUAL); - - glEnable(GL_NORMALIZE); - - glShadeModel(GL_SMOOTH); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glDisable(GL_TEXTURE_2D); - - setupViewport(); - } - - - private void setupViewport() - { - // fix projection for changed size - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - Coord s = disp().getSize(); - glViewport(0, 0, s.xi(), s.yi()); - glOrtho(0, s.x, 0, s.y, -1000, 1000); - - // back to modelview - glMatrixMode(GL_MODELVIEW); - } - - - @Override - protected final void init() - { - keybindings = new KeyBindingPool(); - - addChildSubscriber(keybindings); - - initScreen(); - } - - - @Override - protected final void deinit() - { - deinitScreen(); - } - - - /** - * Initialize screen layout and key bindings.
- * Called during screen construction. - */ - protected abstract void initScreen(); - - /** * Clean up before screen is destroyed. */ @@ -177,13 +125,51 @@ public abstract class Screen extends DelegatingBusClient implements KeyBinder, B /** - * Update animations and timing + * Update animations and timing.
* * @param delta time elapsed */ protected abstract void updateScreen(double delta); + private void setupGraphics() + { + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glDisable(GL_LIGHTING); + + glClearDepth(1f); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + + glEnable(GL_NORMALIZE); + + glShadeModel(GL_SMOOTH); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glDisable(GL_TEXTURE_2D); + + setupViewport(); + } + + + private void setupViewport() + { + // fix projection for changed size + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + Coord s = disp().getSize(); + glViewport(0, 0, s.xi(), s.yi()); + glOrtho(0, s.x, 0, s.y, -1000, 1000); + + // back to modelview + glMatrixMode(GL_MODELVIEW); + } + + /** * Render screen */ @@ -234,9 +220,6 @@ public abstract class Screen extends DelegatingBusClient implements KeyBinder, B renderBegin(); renderScreen(); - - // TODO render layers ? - renderEnd(); } diff --git a/src/mightypork/rogue/display/ScreenLayer.java b/src/mightypork/rogue/display/ScreenLayer.java new file mode 100644 index 0000000..ae5433e --- /dev/null +++ b/src/mightypork/rogue/display/ScreenLayer.java @@ -0,0 +1,58 @@ +package mightypork.rogue.display; + + +import mightypork.rogue.bus.ChildClient; +import mightypork.rogue.display.constraints.RenderContext; +import mightypork.rogue.display.constraints.Renderable; +import mightypork.utils.control.timing.Updateable; +import mightypork.utils.math.coord.Rect; + + +/** + * Screen display layer + * + * @author MightyPork + */ +public abstract class ScreenLayer extends ChildClient implements Renderable, Updateable, RenderContext { + + private Screen screen; + + + public ScreenLayer(Screen screen) { + super(screen); // screen as AppAccess + + this.screen = screen; + } + + + @Override + public abstract void render(); + + + @Override + public abstract void update(double delta); + + + protected Screen screen() + { + return screen; + } + + + /** + * UNSUPPORTED + */ + @Override + public final void setContext(RenderContext context) + { + throw new UnsupportedOperationException("ScreenLayer uses screen as it's context."); + } + + + @Override + public Rect getRect() + { + return screen.getRect(); + } + +} diff --git a/src/mightypork/rogue/display/constraints/BaseConstraint.java b/src/mightypork/rogue/display/constraints/BaseConstraint.java new file mode 100644 index 0000000..4fdac06 --- /dev/null +++ b/src/mightypork/rogue/display/constraints/BaseConstraint.java @@ -0,0 +1,58 @@ +package mightypork.rogue.display.constraints; + + +import mightypork.utils.math.coord.Coord; + + +/** + * A constraint based on a given {@link RenderContext} + * + * @author MightyPork + */ +public abstract class BaseConstraint implements WithContext { + + protected RenderContext context = null; + + + public BaseConstraint(RenderContext context) { + this.context = context; + } + + + @Override + public void setContext(RenderContext context) + { + this.context = context; + } + + + /** + * @return context + */ + public RenderContext getContext() + { + return context; + } + + + /** + * @return context rect origin + */ + protected Coord getOrigin() + { + if (context == null) return Coord.zero(); + + return context.getRect().getOrigin(); + } + + + /** + * @return context rect size + */ + protected Coord getSize() + { + if (context == null) return Coord.zero(); + + return context.getRect().getSize(); + } +} diff --git a/src/mightypork/rogue/display/constraints/Constraint.java b/src/mightypork/rogue/display/constraints/Constraint.java deleted file mode 100644 index 3772fe5..0000000 --- a/src/mightypork/rogue/display/constraints/Constraint.java +++ /dev/null @@ -1,59 +0,0 @@ -package mightypork.rogue.display.constraints; - - -import mightypork.utils.math.coord.Coord; -import mightypork.utils.math.coord.Rect; - - -public abstract class Constraint implements Bounding { - - protected Bounding context; - - - public Constraint(Bounding context) { - this.context = context; - } - - - /** - * Assign a context - * - * @param context - */ - public void setContext(Bounding context) - { - this.context = context; - } - - - /** - * @return context - */ - public Bounding getContext() - { - return context; - } - - - /** - * @return context rect origin - */ - protected Coord origin() - { - return context.getRect().getOrigin(); - } - - - /** - * @return context rect size - */ - protected Coord size() - { - return context.getRect().getSize(); - } - - - @Override - public abstract Rect getRect(); - -} diff --git a/src/mightypork/rogue/display/constraints/ConstraintFactory.java b/src/mightypork/rogue/display/constraints/ConstraintFactory.java new file mode 100644 index 0000000..62744ee --- /dev/null +++ b/src/mightypork/rogue/display/constraints/ConstraintFactory.java @@ -0,0 +1,394 @@ +package mightypork.rogue.display.constraints; + + +import mightypork.utils.control.timing.animation.AnimDouble; +import mightypork.utils.math.coord.Coord; +import mightypork.utils.math.coord.Rect; + + +/** + * Constraint factory.
+ * Import statically for best experience. + * + * @author MightyPork + */ +public class ConstraintFactory { + + public static NumConstraint c_min(final NumConstraint a, final NumConstraint b) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return Math.min(a.getValue(), b.getValue()); + } + }; + } + + + public static NumConstraint c_max(final NumConstraint a, final NumConstraint b) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return Math.max(a.getValue(), b.getValue()); + } + }; + } + + + public static NumConstraint c_abs(final NumConstraint a) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return Math.abs(a.getValue()); + } + }; + } + + + public static NumConstraint c_round(final NumConstraint a) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return Math.round(a.getValue()); + } + }; + } + + + public static RectConstraint c_round(RenderContext context) + { + return new RectConstraint(context) { + + @Override + public Rect getRect() + { + return context.getRect().round(); + } + }; + } + + + public static NumConstraint c_ceil(final NumConstraint a) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return Math.ceil(a.getValue()); + } + }; + } + + + public static NumConstraint c_floor(final NumConstraint a) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return Math.floor(a.getValue()); + } + }; + } + + + public static NumConstraint c_neg(final NumConstraint a) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return -a.getValue(); + } + }; + } + + + public static NumConstraint c_add(final NumConstraint a, final NumConstraint b) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return a.getValue() + b.getValue(); + } + }; + } + + + public static NumConstraint c_sub(final NumConstraint a, final NumConstraint b) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return a.getValue() - b.getValue(); + } + }; + } + + + public static NumConstraint c_mul(final NumConstraint a, final NumConstraint b) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return a.getValue() * b.getValue(); + } + }; + } + + + public static NumConstraint c_div(final NumConstraint a, final NumConstraint b) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return a.getValue() / b.getValue(); + } + }; + } + + + public static NumConstraint c_percent(final NumConstraint whole, final NumConstraint percent) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return whole.getValue() * (percent.getValue() / 100); + } + }; + } + + + public static NumConstraint c_n(final double a) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return a; + } + }; + } + + + public static NumConstraint c_n(final AnimDouble a) + { + return new NumConstraint(null) { + + @Override + public double getValue() + { + return a.getCurrentValue(); + } + }; + } + + + public static NumConstraint c_width(final RenderContext context) + { + return new NumConstraint(context) { + + @Override + public double getValue() + { + return getSize().x; + } + }; + } + + + public static NumConstraint c_height(final RenderContext context) + { + return new NumConstraint(context) { + + @Override + public double getValue() + { + return getSize().y; + } + }; + } + + + public static RectConstraint c_row(RenderContext context, final int rows, final int index) + { + return new RectConstraint(context) { + + @Override + public Rect getRect() + { + double height = context.getRect().getSize().y; + double perRow = height / rows; + + return Rect.fromSize(getOrigin().add(0, perRow * (rows - index - 1)), getSize().setY(perRow)); + } + }; + } + + + public static RectConstraint c_column(RenderContext context, final int columns, final int index) + { + return new RectConstraint(context) { + + @Override + public Rect getRect() + { + double width = context.getRect().getSize().x; + double perCol = width / columns; + + return Rect.fromSize(getOrigin().add(perCol * index, 0), getSize().setX(perCol)); + } + }; + } + + + public static RectConstraint c_shrink(RenderContext context, NumConstraint shrink) + { + return c_shrink(context, shrink, shrink, shrink, shrink); + } + + + public static RectConstraint c_shrink(RenderContext context, NumConstraint horiz, NumConstraint vert) + { + return c_shrink(context, horiz, vert, horiz, vert); + } + + + public static RectConstraint c_shrink(RenderContext context, final NumConstraint left, final NumConstraint top, final NumConstraint right, final NumConstraint bottom) + { + return new RectConstraint(context) { + + @Override + public Rect getRect() + { + return context.getRect().shrink(left.getValue(), top.getValue(), right.getValue(), bottom.getValue()); + } + }; + } + + + public static RectConstraint c_grow(RenderContext context, NumConstraint grow) + { + return c_grow(context, grow, grow, grow, grow); + } + + + public static RectConstraint c_grow(RenderContext context, NumConstraint horiz, NumConstraint vert) + { + return c_grow(context, horiz, vert, horiz, vert); + } + + + public static RectConstraint c_grow(RenderContext context, final NumConstraint left, final NumConstraint top, final NumConstraint right, final NumConstraint bottom) + { + return new RectConstraint(context) { + + @Override + public Rect getRect() + { + return context.getRect().grow(left.getValue(), top.getValue(), right.getValue(), bottom.getValue()); + } + }; + } + + + public static RectConstraint c_tile(RenderContext context, final int rows, final int cols, final int left, final int top) + { + return new RectConstraint(context) { + + @Override + public Rect getRect() + { + double height = getSize().y; + double width = getSize().y; + double perRow = height / rows; + double perCol = width / cols; + + return Rect.fromSize(getOrigin().add(perCol * left, perRow * (rows - top - 1)), perCol, perRow); + } + }; + } + + + public static RectConstraint c_sizedBox(RenderContext context, final NumConstraint left, final NumConstraint bottom, final NumConstraint width, final NumConstraint height) + { + return new RectConstraint(context) { + + @Override + public Rect getRect() + { + Coord origin = getOrigin(); + + //@formatter:off + return Rect.fromSize( + origin.x + left.getValue(), + origin.y + bottom.getValue(), + width.getValue(), + height.getValue() + ); + //@formatter:on + } + }; + } + + + public static RectConstraint c_posBox(RenderContext context, final NumConstraint left, final NumConstraint bottom, final NumConstraint right, final NumConstraint top) + { + return new RectConstraint(context) { + + @Override + public Rect getRect() + { + Coord origin = getOrigin(); + + //@formatter:off + return new Rect( + origin.x + left.getValue(), + origin.y + bottom.getValue(), + origin.x + right.getValue(), + origin.y + top.getValue() + ); + //@formatter:on + } + }; + } + + + public static RectConstraint c_move(RenderContext context, final NumConstraint x, final NumConstraint y) + { + return new RectConstraint(context) { + + @Override + public Rect getRect() + { + return context.getRect().add(x.getValue(), y.getValue()); + } + }; + } + +} diff --git a/src/mightypork/rogue/display/constraints/ElementHolder.java b/src/mightypork/rogue/display/constraints/ElementHolder.java new file mode 100644 index 0000000..e96b4ef --- /dev/null +++ b/src/mightypork/rogue/display/constraints/ElementHolder.java @@ -0,0 +1,95 @@ +package mightypork.rogue.display.constraints; + + +import java.util.LinkedList; + +import mightypork.rogue.AppAccess; +import mightypork.rogue.bus.ChildClient; +import mightypork.utils.math.coord.Rect; + + +public class ElementHolder extends ChildClient implements RenderContext, Renderable { + + private LinkedList elements = new LinkedList(); + private RenderContext context; + + + public ElementHolder(AppAccess app) { + super(app); + } + + + public ElementHolder(AppAccess app, RenderContext context) { + super(app); + this.context = context; + } + + + @Override + public void setContext(RenderContext context) + { + this.context = context; + } + + + /** + * Add element to the holder. + * + * @param elem + */ + public void add(Renderable elem) + { + if (elem == null) return; + elem.setContext(this); + elements.add(elem); + addChildClient(elem); + } + + + /** + * Add element to the holder. + * + * @param elem + * @param constraint + */ + public void add(Renderable elem, RectConstraint constraint) + { + if (elem == null) return; + + constraint.setContext(this); + elem.setContext(constraint); + + elements.add(elem); + addChildClient(elem); + } + + + /** + * Remove element from the holder + * + * @param elem + */ + public void remove(Renderable elem) + { + if (elem == null) return; + elements.remove(elem); + removeChildClient(elem); + } + + + @Override + public void render() + { + for (Renderable element : elements) { + element.render(); + } + } + + + @Override + public Rect getRect() + { + return context.getRect(); + } + +} diff --git a/src/mightypork/rogue/display/constraints/NumConstraint.java b/src/mightypork/rogue/display/constraints/NumConstraint.java new file mode 100644 index 0000000..03d22ee --- /dev/null +++ b/src/mightypork/rogue/display/constraints/NumConstraint.java @@ -0,0 +1,18 @@ +package mightypork.rogue.display.constraints; + + +/** + * Constraint that provides size + * + * @author MightyPork + */ +public abstract class NumConstraint extends BaseConstraint { + + public NumConstraint(RenderContext context) { + super(context); + } + + + public abstract double getValue(); + +} diff --git a/src/mightypork/rogue/display/constraints/RectConstraint.java b/src/mightypork/rogue/display/constraints/RectConstraint.java new file mode 100644 index 0000000..f704a9e --- /dev/null +++ b/src/mightypork/rogue/display/constraints/RectConstraint.java @@ -0,0 +1,22 @@ +package mightypork.rogue.display.constraints; + + +import mightypork.utils.math.coord.Rect; + + +/** + * Constraint that provides a rect (RenderContext) + * + * @author MightyPork + */ +public abstract class RectConstraint extends BaseConstraint implements RenderContext { + + public RectConstraint(RenderContext context) { + super(context); + } + + + @Override + public abstract Rect getRect(); + +} diff --git a/src/mightypork/rogue/display/constraints/Bounding.java b/src/mightypork/rogue/display/constraints/RenderContext.java similarity index 67% rename from src/mightypork/rogue/display/constraints/Bounding.java rename to src/mightypork/rogue/display/constraints/RenderContext.java index 13d0fbe..cb140d0 100644 --- a/src/mightypork/rogue/display/constraints/Bounding.java +++ b/src/mightypork/rogue/display/constraints/RenderContext.java @@ -5,11 +5,11 @@ import mightypork.utils.math.coord.Rect; /** - * Bounding box provider - context for {@link Constraint} + * Bounding box provider - context for {@link RectConstraint} * * @author MightyPork */ -public interface Bounding { +public interface RenderContext { /** * @return bounding rectangle diff --git a/src/mightypork/rogue/display/constraints/Renderable.java b/src/mightypork/rogue/display/constraints/Renderable.java new file mode 100644 index 0000000..ba23ec6 --- /dev/null +++ b/src/mightypork/rogue/display/constraints/Renderable.java @@ -0,0 +1,12 @@ +package mightypork.rogue.display.constraints; + + +public interface Renderable extends WithContext { + + public void render(); + + + @Override + public void setContext(RenderContext context); + +} diff --git a/src/mightypork/rogue/display/constraints/WithContext.java b/src/mightypork/rogue/display/constraints/WithContext.java new file mode 100644 index 0000000..dda2ac5 --- /dev/null +++ b/src/mightypork/rogue/display/constraints/WithContext.java @@ -0,0 +1,12 @@ +package mightypork.rogue.display.constraints; + + +public interface WithContext { + + /** + * Assign a context + * + * @param context + */ + public void setContext(RenderContext context); +} diff --git a/src/mightypork/rogue/display/rendering/Renderable.java b/src/mightypork/rogue/display/rendering/Renderable.java deleted file mode 100644 index cc2a2bf..0000000 --- a/src/mightypork/rogue/display/rendering/Renderable.java +++ /dev/null @@ -1,8 +0,0 @@ -package mightypork.rogue.display.rendering; - - -public interface Renderable { - - public void render(); - -} diff --git a/src/mightypork/rogue/display/rendering/ScreenLayer.java b/src/mightypork/rogue/display/rendering/ScreenLayer.java deleted file mode 100644 index c774de5..0000000 --- a/src/mightypork/rogue/display/rendering/ScreenLayer.java +++ /dev/null @@ -1,84 +0,0 @@ -package mightypork.rogue.display.rendering; - - -import java.util.Collection; -import java.util.LinkedHashSet; - -import mightypork.rogue.AppAdapter; -import mightypork.rogue.bus.UpdateReceiver; -import mightypork.rogue.display.Screen; -import mightypork.rogue.input.KeyBinder; -import mightypork.rogue.input.KeyBindingPool; -import mightypork.rogue.input.KeyStroke; -import mightypork.utils.patterns.subscription.clients.DelegatingClient; -import mightypork.utils.time.Updateable; - - -/** - * Screen layer
- * Plugged into a screen as a child bus subscriber, receiving update and render - * calls directly from the screen. - * - * @author MightyPork - */ -public abstract class ScreenLayer extends AppAdapter implements KeyBinder, DelegatingClient, Renderable, Updateable { - - private Screen screen; - - private KeyBindingPool keybindings; - - private Collection layerChildClients = new LinkedHashSet(); - - - public ScreenLayer(Screen screen) { - super(screen); // screen as AppAccess - - this.screen = screen; - - layerChildClients.add(keybindings = new KeyBindingPool()); - } - - - - @Override - public final void bindKeyStroke(KeyStroke stroke, Runnable task) - { - keybindings.bindKeyStroke(stroke, task); - } - - - @Override - public final void unbindKeyStroke(KeyStroke stroke) - { - keybindings.unbindKeyStroke(stroke); - } - - - @Override - public abstract void render(); - - - @Override - public abstract void update(double delta); - - - protected Screen screen() - { - return screen; - } - - - @Override - public Collection getChildClients() - { - return layerChildClients; - } - - - @Override - public final boolean doesDelegate() - { - return true; - } - -} diff --git a/src/mightypork/rogue/display/ScreenTestAnimations.java b/src/mightypork/rogue/display/screens/ScreenTestAnimations.java similarity index 85% rename from src/mightypork/rogue/display/ScreenTestAnimations.java rename to src/mightypork/rogue/display/screens/ScreenTestAnimations.java index b861e43..664c382 100644 --- a/src/mightypork/rogue/display/ScreenTestAnimations.java +++ b/src/mightypork/rogue/display/screens/ScreenTestAnimations.java @@ -1,18 +1,19 @@ -package mightypork.rogue.display; +package mightypork.rogue.display.screens; import java.util.Random; import mightypork.rogue.AppAccess; import mightypork.rogue.bus.events.MouseButtonEvent; +import mightypork.rogue.display.Screen; import mightypork.rogue.input.KeyStroke; -import mightypork.rogue.util.RenderUtils; +import mightypork.rogue.textures.Render; +import mightypork.utils.control.timing.animation.AnimDouble; +import mightypork.utils.control.timing.animation.AnimDoubleDeg; import mightypork.utils.math.Polar; import mightypork.utils.math.color.RGB; import mightypork.utils.math.coord.Coord; import mightypork.utils.math.easing.Easing; -import mightypork.utils.time.animation.AnimDouble; -import mightypork.utils.time.animation.AnimDoubleDeg; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.Display; @@ -22,6 +23,28 @@ public class ScreenTestAnimations extends Screen implements MouseButtonEvent.Lis public ScreenTestAnimations(AppAccess app) { super(app); + + bindKeyStroke(new KeyStroke(Keyboard.KEY_RIGHT), new Runnable() { + + @Override + public void run() + { + for (AnimDouble a : anims) { + a.animate(0, 1, 1 + rand.nextDouble() * 1); + } + } + }); + + bindKeyStroke(new KeyStroke(Keyboard.KEY_LEFT), new Runnable() { + + @Override + public void run() + { + for (AnimDouble a : anims) { + a.animate(1, 0, 1 + rand.nextDouble() * 1); + } + } + }); } private Random rand = new Random(); @@ -47,9 +70,6 @@ public class ScreenTestAnimations extends Screen implements MouseButtonEvent.Lis new AnimDouble(0, Easing.BOUNCE_OUT), new AnimDouble(0, Easing.BOUNCE_OUT), new AnimDouble(0, Easing.BOUNCE_OUT), - new AnimDouble(0, Easing.BOUNCE_OUT), - new AnimDouble(0, Easing.BOUNCE_OUT), - new AnimDouble(0, Easing.BOUNCE_OUT), // new AnimDouble(0, Easing.NONE), // new AnimDouble(0, Easing.LINEAR), @@ -96,33 +116,6 @@ public class ScreenTestAnimations extends Screen implements MouseButtonEvent.Lis }; //@formatter:on - @Override - public void initScreen() - { - bindKeyStroke(new KeyStroke(Keyboard.KEY_RIGHT), new Runnable() { - - @Override - public void run() - { - for (AnimDouble a : anims) { - a.animate(0, 1, 1 + rand.nextDouble() * 1); - } - } - }); - - bindKeyStroke(new KeyStroke(Keyboard.KEY_LEFT), new Runnable() { - - @Override - public void run() - { - for (AnimDouble a : anims) { - a.animate(1, 0, 1 + rand.nextDouble() * 1); - } - } - }); - } - - @Override protected void deinitScreen() { @@ -167,14 +160,14 @@ public class ScreenTestAnimations extends Screen implements MouseButtonEvent.Lis for (int i = 0; i < anims.length; i++) { AnimDouble a = anims[i]; - RenderUtils.setColor(RGB.GREEN); - RenderUtils.quadSize(padding + a.getCurrentValue() * (screenW - perBoxH), screenH - perBoxH * i - perBoxH + padding, boxSide, boxSide); + Render.setColor(RGB.GREEN); + Render.quadSize(padding + a.getCurrentValue() * (screenW - perBoxH), screenH - perBoxH * i - perBoxH + padding, boxSide, boxSide); } - RenderUtils.setColor(RGB.YELLOW); - RenderUtils.translate(new Coord(Display.getWidth() / 2, Display.getHeight() / 2)); - RenderUtils.rotateZ(degAnim.getCurrentValue()); - RenderUtils.quadSize(-10, -10, 20, 200); + Render.setColor(RGB.YELLOW); + Render.translate(new Coord(Display.getWidth() / 2, Display.getHeight() / 2)); + Render.rotateZ(degAnim.getCurrentValue()); + Render.quadSize(-10, -10, 20, 200); } diff --git a/src/mightypork/rogue/display/screens/screenBouncy/BouncyBox.java b/src/mightypork/rogue/display/screens/screenBouncy/BouncyBox.java new file mode 100644 index 0000000..380d623 --- /dev/null +++ b/src/mightypork/rogue/display/screens/screenBouncy/BouncyBox.java @@ -0,0 +1,87 @@ +package mightypork.rogue.display.screens.screenBouncy; + + +import static mightypork.rogue.display.constraints.ConstraintFactory.*; + +import java.util.Random; + +import mightypork.rogue.display.constraints.NumConstraint; +import mightypork.rogue.display.constraints.RectConstraint; +import mightypork.rogue.display.constraints.RenderContext; +import mightypork.rogue.display.constraints.Renderable; +import mightypork.rogue.textures.Render; +import mightypork.utils.control.timing.Updateable; +import mightypork.utils.control.timing.animation.AnimDouble; +import mightypork.utils.math.color.RGB; +import mightypork.utils.math.coord.Rect; +import mightypork.utils.math.easing.Easing; + + +public class BouncyBox implements Renderable, Updateable, RenderContext { + + private Random rand = new Random(); + + private RenderContext context; + + private RectConstraint box; + + private AnimDouble pos = new AnimDouble(0, Easing.BOUNCE_OUT); + + + public BouncyBox() { + NumConstraint side = c_height(this); + + NumConstraint move_length = c_sub(c_width(this), side); + + NumConstraint offset = c_mul(move_length, c_n(pos)); + + RectConstraint abox = c_sizedBox(this, offset, c_n(0), side, side); + + NumConstraint margin = c_percent(side, c_n(10)); + + RectConstraint with_margin = c_shrink(abox, margin); + + box = with_margin; + } + + + @Override + public Rect getRect() + { + return context.getRect(); + } + + + @Override + public void render() + { + Render.quadRect(box.getRect(), RGB.GREEN); + } + + + @Override + public void setContext(RenderContext context) + { + this.context = context; + } + + + public void goLeft() + { + pos.animate(1, 0, 2 + rand.nextDouble() * 1); + } + + + public void goRight() + { + pos.animate(0, 1, 2 + rand.nextDouble() * 1); + } + + + @Override + public void update(double delta) + { + pos.update(delta); + } + +} diff --git a/src/mightypork/rogue/display/screens/screenBouncy/LayerBouncyBoxes.java b/src/mightypork/rogue/display/screens/screenBouncy/LayerBouncyBoxes.java new file mode 100644 index 0000000..e4dca95 --- /dev/null +++ b/src/mightypork/rogue/display/screens/screenBouncy/LayerBouncyBoxes.java @@ -0,0 +1,64 @@ +package mightypork.rogue.display.screens.screenBouncy; + + +import static mightypork.rogue.display.constraints.ConstraintFactory.*; + +import java.util.ArrayList; +import java.util.List; + +import mightypork.rogue.display.Screen; +import mightypork.rogue.display.ScreenLayer; +import mightypork.rogue.display.constraints.ElementHolder; + + +public class LayerBouncyBoxes extends ScreenLayer { + + List boxes = new ArrayList(); + private ElementHolder layout; + + + public LayerBouncyBoxes(Screen screen) { + super(screen); + + layout = new ElementHolder(screen, c_shrink(this, c_percent(c_height(this), c_n(8)))); + addChildClient(layout); + + for (int i = 0; i < 32; i++) { + BouncyBox bbr = new BouncyBox(); + layout.add(bbr, c_row(null, 32, i)); + boxes.add(bbr); + } + + } + + + @Override + public void render() + { + layout.render(); + } + + + @Override + public void update(double delta) + { + // no impl + } + + + public void goLeft() + { + for (BouncyBox bbr : boxes) { + bbr.goLeft(); + } + } + + + public void goRight() + { + for (BouncyBox bbr : boxes) { + bbr.goRight(); + } + } + +} diff --git a/src/mightypork/rogue/display/screens/screenBouncy/TestLayeredScreen.java b/src/mightypork/rogue/display/screens/screenBouncy/TestLayeredScreen.java new file mode 100644 index 0000000..134317a --- /dev/null +++ b/src/mightypork/rogue/display/screens/screenBouncy/TestLayeredScreen.java @@ -0,0 +1,70 @@ +package mightypork.rogue.display.screens.screenBouncy; + + +import mightypork.rogue.AppAccess; +import mightypork.rogue.display.LayeredScreen; +import mightypork.rogue.input.KeyStroke; + +import org.lwjgl.input.Keyboard; + + +public class TestLayeredScreen extends LayeredScreen { + + private LayerBouncyBoxes layer; + + + public TestLayeredScreen(AppAccess app) { + super(app); + + layer = new LayerBouncyBoxes(this); + + addLayer(layer); + + bindKeyStroke(new KeyStroke(Keyboard.KEY_RIGHT), new Runnable() { + + @Override + public void run() + { + layer.goRight(); + } + }); + + bindKeyStroke(new KeyStroke(Keyboard.KEY_LEFT), new Runnable() { + + @Override + public void run() + { + layer.goLeft(); + } + }); + } + + + @Override + protected void deinitScreen() + { + // no impl + } + + + @Override + protected void onScreenEnter() + { + // no impl + } + + + @Override + protected void onScreenLeave() + { + // no impl + } + + + @Override + protected void updateScreen(double delta) + { + // no impl + } + +} diff --git a/src/mightypork/rogue/input/InputSystem.java b/src/mightypork/rogue/input/InputSystem.java index 452079b..946c44f 100644 --- a/src/mightypork/rogue/input/InputSystem.java +++ b/src/mightypork/rogue/input/InputSystem.java @@ -2,10 +2,11 @@ package mightypork.rogue.input; import mightypork.rogue.AppAccess; -import mightypork.rogue.bus.DelegatingBusClient; +import mightypork.rogue.bus.Subsystem; import mightypork.rogue.bus.events.KeyboardEvent; import mightypork.rogue.bus.events.MouseButtonEvent; import mightypork.rogue.bus.events.MouseMotionEvent; +import mightypork.utils.control.timing.Updateable; import mightypork.utils.math.coord.Coord; import org.lwjgl.LWJGLException; @@ -14,32 +15,27 @@ import org.lwjgl.input.Mouse; import org.lwjgl.opengl.Display; -public class InputSystem extends DelegatingBusClient implements KeyBinder { +public class InputSystem extends Subsystem implements Updateable, KeyBinder { // listeners private KeyBindingPool keybindings; public InputSystem(AppAccess app) { - super(app, true); - } - - - @Override - protected void init() - { + super(app); + initDevices(); initChannels(); // global keybindings keybindings = new KeyBindingPool(); - addChildSubscriber(keybindings); + addChildClient(keybindings); } @Override - public void deinit() + public final void deinit() { Mouse.destroy(); Keyboard.destroy(); @@ -67,7 +63,7 @@ public class InputSystem extends DelegatingBusClient implements KeyBinder { @Override - public void bindKeyStroke(KeyStroke stroke, Runnable task) + public final void bindKeyStroke(KeyStroke stroke, Runnable task) { keybindings.bindKeyStroke(stroke, task); } diff --git a/src/mightypork/rogue/sounds/AudioX.java b/src/mightypork/rogue/sounds/AudioX.java index 8be9178..e309b38 100644 --- a/src/mightypork/rogue/sounds/AudioX.java +++ b/src/mightypork/rogue/sounds/AudioX.java @@ -1,10 +1,10 @@ package mightypork.rogue.sounds; +import mightypork.utils.control.Destroyable; import mightypork.utils.files.FileUtils; import mightypork.utils.logging.Log; import mightypork.utils.math.coord.Coord; -import mightypork.utils.patterns.Destroyable; import org.newdawn.slick.openal.Audio; import org.newdawn.slick.openal.SoundStore; diff --git a/src/mightypork/rogue/sounds/LoopPlayer.java b/src/mightypork/rogue/sounds/LoopPlayer.java index c15f821..447f444 100644 --- a/src/mightypork/rogue/sounds/LoopPlayer.java +++ b/src/mightypork/rogue/sounds/LoopPlayer.java @@ -1,10 +1,10 @@ package mightypork.rogue.sounds; +import mightypork.utils.control.timing.Pauseable; +import mightypork.utils.control.timing.Updateable; +import mightypork.utils.control.timing.animation.AnimDouble; import mightypork.utils.objects.Mutable; -import mightypork.utils.time.Pauseable; -import mightypork.utils.time.Updateable; -import mightypork.utils.time.animation.AnimDouble; import org.lwjgl.openal.AL10; diff --git a/src/mightypork/rogue/sounds/SoundSystem.java b/src/mightypork/rogue/sounds/SoundSystem.java index df78027..b56dba7 100644 --- a/src/mightypork/rogue/sounds/SoundSystem.java +++ b/src/mightypork/rogue/sounds/SoundSystem.java @@ -8,7 +8,8 @@ import java.util.Map; import java.util.Set; import mightypork.rogue.AppAccess; -import mightypork.rogue.bus.DelegatingBusClient; +import mightypork.rogue.bus.Subsystem; +import mightypork.utils.control.timing.Updateable; import mightypork.utils.logging.Log; import mightypork.utils.math.Calc.Buffers; import mightypork.utils.math.coord.Coord; @@ -25,7 +26,7 @@ import org.newdawn.slick.openal.SoundStore; * @author MightyPork */ @SuppressWarnings("unchecked") -public class SoundSystem extends DelegatingBusClient { +public class SoundSystem extends Subsystem implements Updateable { private static final Coord INITIAL_LISTENER_POS = new Coord(0, 0, 0); private static final int MAX_SOURCES = 256; @@ -78,19 +79,12 @@ public class SoundSystem extends DelegatingBusClient { public SoundSystem(AppAccess app) { - super(app, true); + super(app); } @Override - protected void init() - { - // empty - } - - - @Override - public void deinit() + public final void deinit() { for (AudioX r : resources) { r.destroy(); diff --git a/src/mightypork/rogue/testing/TestConstraints.java b/src/mightypork/rogue/testing/TestConstraints.java deleted file mode 100644 index 45864a0..0000000 --- a/src/mightypork/rogue/testing/TestConstraints.java +++ /dev/null @@ -1,84 +0,0 @@ -package mightypork.rogue.testing; - - -import mightypork.rogue.display.constraints.Bounding; -import mightypork.rogue.display.constraints.Constraint; -import mightypork.utils.math.coord.Coord; -import mightypork.utils.math.coord.Rect; - - -public class TestConstraints { - - public static void main(String[] args) - { - Bounding context = new Bounding() { - - @Override - public Rect getRect() - { - return Rect.fromSize(new Coord(0, 0), new Coord(400, 300)); - } - }; - - class Navbar extends Constraint { - - private double height; - - - public Navbar(Bounding context, double height) { - super(context); - this.height = height; - } - - - @Override - public Rect getRect() - { - return Rect.fromSize(origin().setY(size().y - height), size().setY(height)); - } - } - - class TileHorizontal extends Constraint { - - private int count; - private int tile; - - - public TileHorizontal(Bounding context, int tileCount, int aTile) { - super(context); - this.count = tileCount; - setTile(aTile); - } - - - public void setTile(int aTile) - { - if (aTile > count) throw new IndexOutOfBoundsException("Tile count exceeded: " + aTile + " max: " + count); - this.tile = aTile; - } - - - @Override - public Rect getRect() - { - Coord size = size().mul(1D / count, 1); - return Rect.fromSize(origin().add(size.x * tile, 0), size); - } - } - - Navbar nb = new Navbar(context, 100); - - TileHorizontal tile = new TileHorizontal(nb, 5, 0); - - for (int i = 0; i < 5; i++) { - tile.setTile(i); - - System.out.println(tile.getRect()); - } - - System.out.println("nb:" + nb.getRect()); - - System.out.println("ctx:" + context.getRect()); - } - -} diff --git a/src/mightypork/rogue/testing/TestMsgbus.java b/src/mightypork/rogue/testing/TestMsgbus.java deleted file mode 100644 index 7e473b6..0000000 --- a/src/mightypork/rogue/testing/TestMsgbus.java +++ /dev/null @@ -1,219 +0,0 @@ -package mightypork.rogue.testing; - - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import mightypork.utils.logging.Log; -import mightypork.utils.patterns.subscription.Handleable; -import mightypork.utils.patterns.subscription.MessageBus; -import mightypork.utils.patterns.subscription.clients.DelegatingClient; -import mightypork.utils.patterns.subscription.clients.ToggleableClient; - - -public class TestMsgbus { - - public static void main(String[] args) - { - Log.create("runtime", new File("."), 0); - - MessageBus bus = new MessageBus(); - - bus.createChannel(StringMessage.class, StringMessage.Listener.class); - bus.createChannel(IntMessage.class, IntMessage.Listener.class); - - Delegator deleg1 = new Delegator("Deleg1"); - Delegator deleg2 = new Delegator("Deleg2"); - Toggleable togg1 = new Toggleable("Tog1"); - Toggleable togg2 = new Toggleable("Tog2"); - Toggleable plain1 = new Toggleable("Plain1"); - Toggleable plain2 = new Toggleable("Plain2"); - Toggleable plain3 = new Toggleable("Plain3"); - - PlainInt pint = new PlainInt("Ints"); - PlainBoth pboth = new PlainBoth("Both"); - - bus.subscribe(deleg1); - - deleg1.clients.add(togg1); - deleg1.clients.add(plain2); - deleg1.clients.add(deleg2); - deleg1.clients.add(pint); - - deleg2.clients.add(deleg1); - deleg2.clients.add(togg1); - deleg2.clients.add(plain3); - deleg2.clients.add(pboth); - - bus.subscribe(plain1); - - bus.subscribe(togg2); - - bus.broadcast(new StringMessage("")); - bus.broadcast(new IntMessage(7)); - bus.broadcast(new IntMessage(13)); - - deleg2.delegating = false; - - bus.broadcast(new IntMessage(44)); - - deleg2.delegating = true; - - bus.broadcast(new IntMessage(45)); - - } - -} - - -class Delegator extends Plain implements DelegatingClient { - - List clients = new ArrayList(); - boolean delegating = true; - - - public Delegator(String name) { - super(name); - } - - - @Override - public Collection getChildClients() - { - return clients; - } - - - @Override - public boolean doesDelegate() - { - return delegating; - } -} - - -class Toggleable extends Plain implements ToggleableClient { - - boolean subscribing = true; - - - public Toggleable(String name) { - super(name); - } - - - @Override - public boolean doesSubscribe() - { - return subscribing; - } -} - - -class Plain implements StringMessage.Listener { - - String name; - - - public Plain(String name) { - this.name = name; - } - - - @Override - public void receive(StringMessage message) - { - System.out.println(name + " (STR) RECV: " + message.s); - } -} - - -class PlainInt implements IntMessage.Listener { - - String name; - - - public PlainInt(String name) { - this.name = name; - } - - - @Override - public void receive(IntMessage message) - { - System.out.println(name + " (INT) RECV: " + message.i); - } -} - - -class PlainBoth implements IntMessage.Listener, StringMessage.Listener { - - String name; - - - public PlainBoth(String name) { - this.name = name; - } - - - @Override - public void receive(IntMessage message) - { - System.out.println(name + " (both-INT) RECV: " + message.i); - } - - - @Override - public void receive(StringMessage message) - { - System.out.println(name + " (both-STR) RECV: " + message.s); - } -} - - -class StringMessage implements Handleable { - - String s; - - - StringMessage(String str) { - this.s = str; - } - - public interface Listener { - - public void receive(StringMessage message); - } - - - @Override - public void handleBy(Listener handler) - { - handler.receive(this); - } -} - - -class IntMessage implements Handleable { - - int i; - - - IntMessage(int i) { - this.i = i; - } - - public interface Listener { - - public void receive(IntMessage message); - } - - - @Override - public void handleBy(Listener handler) - { - handler.receive(this); - } -} diff --git a/src/mightypork/rogue/util/RenderUtils.java b/src/mightypork/rogue/textures/Render.java similarity index 90% rename from src/mightypork/rogue/util/RenderUtils.java rename to src/mightypork/rogue/textures/Render.java index a22b3af..0340b0f 100644 --- a/src/mightypork/rogue/util/RenderUtils.java +++ b/src/mightypork/rogue/textures/Render.java @@ -1,15 +1,20 @@ -package mightypork.rogue.util; +package mightypork.rogue.textures; import static org.lwjgl.opengl.GL11.*; -import mightypork.rogue.textures.TextureManager; -import mightypork.rogue.textures.TxQuad; + +import java.io.IOException; + +import mightypork.utils.files.FileUtils; +import mightypork.utils.logging.Log; import mightypork.utils.math.color.HSV; import mightypork.utils.math.color.RGB; import mightypork.utils.math.coord.Coord; import mightypork.utils.math.coord.Rect; import org.newdawn.slick.opengl.Texture; +import org.newdawn.slick.opengl.TextureLoader; +import org.newdawn.slick.util.ResourceLoader; /** @@ -17,12 +22,15 @@ import org.newdawn.slick.opengl.Texture; * * @author MightyPork */ -public class RenderUtils { +public class Render { private static final Coord AXIS_X = new Coord(1, 0, 0); private static final Coord AXIS_Y = new Coord(0, 1, 0); private static final Coord AXIS_Z = new Coord(0, 0, 1); + public static Texture lastBinded = null; + private static boolean inited = false; + /** * Render quad 2D @@ -85,18 +93,18 @@ public class RenderUtils { { double bdr = border; - RenderUtils.setColor(borderColor); + setColor(borderColor); //@formatter:off - RenderUtils.quadCoord(minX, minY, minX + bdr, maxY); - RenderUtils.quadCoord(maxX - bdr, minY, maxX, maxY); - RenderUtils.quadCoord(minX + bdr, maxY - bdr, maxX - bdr, maxY); - RenderUtils.quadCoord(minX + bdr, minY, maxX - bdr, minY + bdr); + quadCoord(minX, minY, minX + bdr, maxY); + quadCoord(maxX - bdr, minY, maxX, maxY); + quadCoord(minX + bdr, maxY - bdr, maxX - bdr, maxY); + quadCoord(minX + bdr, minY, maxX - bdr, minY + bdr); //@formatter:on if (insideColor != null) { - RenderUtils.setColor(insideColor); - RenderUtils.quadCoord(minX + bdr, minY + bdr, maxX - bdr, maxY - bdr); + setColor(insideColor); + quadCoord(minX + bdr, minY + bdr, maxX - bdr, maxY - bdr); } } @@ -329,7 +337,7 @@ public class RenderUtils { double bdr = border; - RenderUtils.setColor(leftTopC); + setColor(leftTopC); // left + top glBegin(GL_QUADS); @@ -344,7 +352,7 @@ public class RenderUtils { glVertex2d(maxX, maxY); glEnd(); - RenderUtils.setColor(rightBottomC); + setColor(rightBottomC); // right + bottom glBegin(GL_QUADS); @@ -359,8 +367,8 @@ public class RenderUtils { glVertex2d(minX + bdr, minY + bdr); glEnd(); - RenderUtils.setColor(fill); - RenderUtils.quadCoord(minX + bdr, minY + bdr, maxX - bdr, maxY - bdr); + setColor(fill); + quadCoord(minX + bdr, minY + bdr, maxX - bdr, maxY - bdr); } @@ -524,11 +532,11 @@ public class RenderUtils { { glEnable(GL_TEXTURE_2D); setColor(tint); - TextureManager.bind(texture); + bindTexture(texture); quadTexturedAbs(quad, txCoords.mul(1 / texture.getImageHeight())); - TextureManager.unbind(); + unbindTexture(); glDisable(GL_TEXTURE_2D); } @@ -946,4 +954,78 @@ public class RenderUtils { Coord vec = axis.norm(1); glRotated(angle, vec.x, vec.y, vec.z); } + + + public static void push() + { + glPushMatrix(); + } + + + public static void pop() + { + glPopMatrix(); + } + + + /** + * Load texture + * + * @param resourcePath + * @return the loaded texture + */ + public static Texture loadTexture(String resourcePath) + { + if (!inited) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + inited = true; + } + + try { + + String ext = FileUtils.getExtension(resourcePath); + + Texture texture = TextureLoader.getTexture(ext.toUpperCase(), ResourceLoader.getResourceAsStream(resourcePath)); + + if (texture == null) { + Log.w("Texture " + resourcePath + " could not be loaded."); + } + + return texture; + + } catch (IOException e) { + Log.e("Loading of texture " + resourcePath + " failed.", e); + throw new RuntimeException(e); + } + + } + + + /** + * Bind texture + * + * @param texture the texture + * @throws RuntimeException if not loaded yet + */ + public static void bindTexture(Texture texture) throws RuntimeException + { + if (texture != lastBinded) { + glBindTexture(GL_TEXTURE_2D, 0); + glBindTexture(GL_TEXTURE_2D, texture.getTextureID()); + lastBinded = texture; + } + } + + + /** + * Unbind all + */ + public static void unbindTexture() + { + glBindTexture(GL_TEXTURE_2D, 0); + lastBinded = null; + } } diff --git a/src/mightypork/rogue/textures/TextureManager.java b/src/mightypork/rogue/textures/TextureManager.java deleted file mode 100644 index 7a699ff..0000000 --- a/src/mightypork/rogue/textures/TextureManager.java +++ /dev/null @@ -1,76 +0,0 @@ -package mightypork.rogue.textures; - - -import static org.lwjgl.opengl.GL11.*; - -import java.io.IOException; - -import mightypork.utils.logging.Log; - -import org.newdawn.slick.opengl.Texture; -import org.newdawn.slick.opengl.TextureLoader; -import org.newdawn.slick.util.ResourceLoader; - - -/** - * Texture manager - * - * @author MightyPork - */ -public class TextureManager { - - private static Texture lastBinded = null; - - - /** - * Load texture - * - * @param resourcePath - * @return the loaded texture - */ - public static Texture load(String resourcePath) - { - try { - String ext = resourcePath.substring(resourcePath.length() - 4); - - Texture texture = TextureLoader.getTexture(ext.toUpperCase(), ResourceLoader.getResourceAsStream(resourcePath)); - - if (texture != null) { - return texture; - } - - Log.w("Texture " + resourcePath + " could not be loaded."); - return null; - } catch (IOException e) { - Log.e("Loading of texture " + resourcePath + " failed.", e); - throw new RuntimeException(e); - } - - } - - - /** - * Bind texture - * - * @param texture the texture - * @throws RuntimeException if not loaded yet - */ - public static void bind(Texture texture) throws RuntimeException - { - if (texture != lastBinded) { - glBindTexture(GL_TEXTURE_2D, 0); - glBindTexture(GL_TEXTURE_2D, texture.getTextureID()); - lastBinded = texture; - } - } - - - /** - * Unbind all - */ - public static void unbind() - { - glBindTexture(GL_TEXTURE_2D, 0); - lastBinded = null; - } -} diff --git a/src/mightypork/rogue/textures/Textures.java b/src/mightypork/rogue/textures/Textures.java deleted file mode 100644 index 14edc33..0000000 --- a/src/mightypork/rogue/textures/Textures.java +++ /dev/null @@ -1,40 +0,0 @@ -package mightypork.rogue.textures; - - -import static org.lwjgl.opengl.GL11.*; - -import org.newdawn.slick.opengl.Texture; - - -// TODO rewrite to use hashmap with keys - -/** - * Texture loading class - * - * @author MightyPork - */ -public class Textures { - - protected static Texture logo; - - private static final String GUI = "res/images/gui/"; - - - /** - * Load what's needed for splash - */ - public static void load() - { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - - logo = TextureManager.load(GUI + "logo.png"); - - Tx.initForSplash(); - glDisable(GL_TEXTURE_2D); - Tx.init(); - } - -} diff --git a/src/mightypork/rogue/textures/Tx.java b/src/mightypork/rogue/textures/Tx.java deleted file mode 100644 index 0933b71..0000000 --- a/src/mightypork/rogue/textures/Tx.java +++ /dev/null @@ -1,30 +0,0 @@ -package mightypork.rogue.textures; - - -// TODO rewrite - -/** - * List of texture quads for GUIs - * - * @author MightyPork - */ -public class Tx { - - // logo - public static TxQuad LOGO; - - - public static void initForSplash() - { - // splash logo - LOGO = TxQuad.fromSize(Textures.logo, 15, 9, 226, 132); - } - - - public static void init() - { - // title image (word art) - - } - -} diff --git a/src/mightypork/utils/patterns/Destroyable.java b/src/mightypork/utils/control/Destroyable.java similarity index 83% rename from src/mightypork/utils/patterns/Destroyable.java rename to src/mightypork/utils/control/Destroyable.java index 43f3b45..fa52630 100644 --- a/src/mightypork/utils/patterns/Destroyable.java +++ b/src/mightypork/utils/control/Destroyable.java @@ -1,4 +1,4 @@ -package mightypork.utils.patterns; +package mightypork.utils.control; /** diff --git a/src/mightypork/utils/patterns/subscription/Handleable.java b/src/mightypork/utils/control/bus/Handleable.java similarity index 85% rename from src/mightypork/utils/patterns/subscription/Handleable.java rename to src/mightypork/utils/control/bus/Handleable.java index 7a0998e..28122c8 100644 --- a/src/mightypork/utils/patterns/subscription/Handleable.java +++ b/src/mightypork/utils/control/bus/Handleable.java @@ -1,4 +1,4 @@ -package mightypork.utils.patterns.subscription; +package mightypork.utils.control.bus; /** diff --git a/src/mightypork/utils/patterns/subscription/MessageBus.java b/src/mightypork/utils/control/bus/MessageBus.java similarity index 98% rename from src/mightypork/utils/patterns/subscription/MessageBus.java rename to src/mightypork/utils/control/bus/MessageBus.java index 9d19830..596185f 100644 --- a/src/mightypork/utils/patterns/subscription/MessageBus.java +++ b/src/mightypork/utils/control/bus/MessageBus.java @@ -1,4 +1,4 @@ -package mightypork.utils.patterns.subscription; +package mightypork.utils.control.bus; import java.util.Collection; diff --git a/src/mightypork/utils/patterns/subscription/MessageChannel.java b/src/mightypork/utils/control/bus/MessageChannel.java similarity index 93% rename from src/mightypork/utils/patterns/subscription/MessageChannel.java rename to src/mightypork/utils/control/bus/MessageChannel.java index 379a0fd..159992b 100644 --- a/src/mightypork/utils/patterns/subscription/MessageChannel.java +++ b/src/mightypork/utils/control/bus/MessageChannel.java @@ -1,12 +1,12 @@ -package mightypork.utils.patterns.subscription; +package mightypork.utils.control.bus; import java.util.Collection; import java.util.HashSet; +import mightypork.utils.control.bus.clients.DelegatingClient; +import mightypork.utils.control.bus.clients.ToggleableClient; import mightypork.utils.logging.Log; -import mightypork.utils.patterns.subscription.clients.DelegatingClient; -import mightypork.utils.patterns.subscription.clients.ToggleableClient; /** @@ -64,7 +64,7 @@ final public class MessageChannel, CLIENT> { // opt-out if (client instanceof ToggleableClient) { - if (!((ToggleableClient) client).doesSubscribe()) { + if (!((ToggleableClient) client).isListening()) { continue; } } diff --git a/src/mightypork/utils/patterns/subscription/clients/DelegatingClient.java b/src/mightypork/utils/control/bus/clients/DelegatingClient.java similarity index 86% rename from src/mightypork/utils/patterns/subscription/clients/DelegatingClient.java rename to src/mightypork/utils/control/bus/clients/DelegatingClient.java index 88cb134..050e25d 100644 --- a/src/mightypork/utils/patterns/subscription/clients/DelegatingClient.java +++ b/src/mightypork/utils/control/bus/clients/DelegatingClient.java @@ -1,4 +1,4 @@ -package mightypork.utils.patterns.subscription.clients; +package mightypork.utils.control.bus.clients; import java.util.Collection; diff --git a/src/mightypork/utils/patterns/subscription/clients/ToggleableClient.java b/src/mightypork/utils/control/bus/clients/ToggleableClient.java similarity index 68% rename from src/mightypork/utils/patterns/subscription/clients/ToggleableClient.java rename to src/mightypork/utils/control/bus/clients/ToggleableClient.java index 30c302a..44bad98 100644 --- a/src/mightypork/utils/patterns/subscription/clients/ToggleableClient.java +++ b/src/mightypork/utils/control/bus/clients/ToggleableClient.java @@ -1,4 +1,4 @@ -package mightypork.utils.patterns.subscription.clients; +package mightypork.utils.control.bus.clients; /** @@ -11,6 +11,6 @@ public interface ToggleableClient { /** * @return true if the client wants to receive messages */ - public boolean doesSubscribe(); + public boolean isListening(); } diff --git a/src/mightypork/utils/time/FpsMeter.java b/src/mightypork/utils/control/timing/FpsMeter.java similarity index 96% rename from src/mightypork/utils/time/FpsMeter.java rename to src/mightypork/utils/control/timing/FpsMeter.java index c9a36cf..2add6c7 100644 --- a/src/mightypork/utils/time/FpsMeter.java +++ b/src/mightypork/utils/control/timing/FpsMeter.java @@ -1,4 +1,4 @@ -package mightypork.utils.time; +package mightypork.utils.control.timing; /** diff --git a/src/mightypork/utils/time/Pauseable.java b/src/mightypork/utils/control/timing/Pauseable.java similarity index 83% rename from src/mightypork/utils/time/Pauseable.java rename to src/mightypork/utils/control/timing/Pauseable.java index 9c0efbb..6b6c7e4 100644 --- a/src/mightypork/utils/time/Pauseable.java +++ b/src/mightypork/utils/control/timing/Pauseable.java @@ -1,4 +1,4 @@ -package mightypork.utils.time; +package mightypork.utils.control.timing; public interface Pauseable { diff --git a/src/mightypork/utils/time/TimerDelta.java b/src/mightypork/utils/control/timing/TimerDelta.java similarity index 94% rename from src/mightypork/utils/time/TimerDelta.java rename to src/mightypork/utils/control/timing/TimerDelta.java index 64cefe6..9642e8b 100644 --- a/src/mightypork/utils/time/TimerDelta.java +++ b/src/mightypork/utils/control/timing/TimerDelta.java @@ -1,4 +1,4 @@ -package mightypork.utils.time; +package mightypork.utils.control.timing; /** diff --git a/src/mightypork/utils/time/TimerInterpolating.java b/src/mightypork/utils/control/timing/TimerFps.java similarity index 94% rename from src/mightypork/utils/time/TimerInterpolating.java rename to src/mightypork/utils/control/timing/TimerFps.java index 292a213..357f700 100644 --- a/src/mightypork/utils/time/TimerInterpolating.java +++ b/src/mightypork/utils/control/timing/TimerFps.java @@ -1,4 +1,4 @@ -package mightypork.utils.time; +package mightypork.utils.control.timing; /** @@ -6,7 +6,7 @@ package mightypork.utils.time; * * @author MightyPork */ -public class TimerInterpolating { +public class TimerFps { private long lastFrame = 0; private long nextFrame = 0; @@ -22,7 +22,7 @@ public class TimerInterpolating { * * @param fps target FPS */ - public TimerInterpolating(long fps) { + public TimerFps(long fps) { FRAME = Math.round(SECOND / fps); lastFrame = System.nanoTime(); diff --git a/src/mightypork/utils/control/timing/UpdateEvent.java b/src/mightypork/utils/control/timing/UpdateEvent.java new file mode 100644 index 0000000..2fb5b40 --- /dev/null +++ b/src/mightypork/utils/control/timing/UpdateEvent.java @@ -0,0 +1,22 @@ +package mightypork.utils.control.timing; + + +import mightypork.utils.control.bus.Handleable; + + +public class UpdateEvent implements Handleable { + + private final double deltaTime; + + + public UpdateEvent(double deltaTime) { + this.deltaTime = deltaTime; + } + + + @Override + public void handleBy(Updateable handler) + { + handler.update(deltaTime); + } +} diff --git a/src/mightypork/utils/time/Updateable.java b/src/mightypork/utils/control/timing/Updateable.java similarity index 86% rename from src/mightypork/utils/time/Updateable.java rename to src/mightypork/utils/control/timing/Updateable.java index 6b784ac..1b5c89f 100644 --- a/src/mightypork/utils/time/Updateable.java +++ b/src/mightypork/utils/control/timing/Updateable.java @@ -1,4 +1,4 @@ -package mightypork.utils.time; +package mightypork.utils.control.timing; /** diff --git a/src/mightypork/utils/time/animation/AnimDouble.java b/src/mightypork/utils/control/timing/animation/AnimDouble.java similarity index 96% rename from src/mightypork/utils/time/animation/AnimDouble.java rename to src/mightypork/utils/control/timing/animation/AnimDouble.java index dc0fe78..7785f05 100644 --- a/src/mightypork/utils/time/animation/AnimDouble.java +++ b/src/mightypork/utils/control/timing/animation/AnimDouble.java @@ -1,10 +1,10 @@ -package mightypork.utils.time.animation; +package mightypork.utils.control.timing.animation; +import mightypork.utils.control.timing.Pauseable; +import mightypork.utils.control.timing.Updateable; import mightypork.utils.math.Calc; import mightypork.utils.math.easing.Easing; -import mightypork.utils.time.Pauseable; -import mightypork.utils.time.Updateable; /** diff --git a/src/mightypork/utils/time/animation/AnimDoubleDeg.java b/src/mightypork/utils/control/timing/animation/AnimDoubleDeg.java similarity index 94% rename from src/mightypork/utils/time/animation/AnimDoubleDeg.java rename to src/mightypork/utils/control/timing/animation/AnimDoubleDeg.java index 702edad..860a2a7 100644 --- a/src/mightypork/utils/time/animation/AnimDoubleDeg.java +++ b/src/mightypork/utils/control/timing/animation/AnimDoubleDeg.java @@ -1,4 +1,4 @@ -package mightypork.utils.time.animation; +package mightypork.utils.control.timing.animation; import mightypork.utils.math.Calc; diff --git a/src/mightypork/utils/time/animation/AnimDoubleRad.java b/src/mightypork/utils/control/timing/animation/AnimDoubleRad.java similarity index 94% rename from src/mightypork/utils/time/animation/AnimDoubleRad.java rename to src/mightypork/utils/control/timing/animation/AnimDoubleRad.java index caa9fce..a3cf042 100644 --- a/src/mightypork/utils/time/animation/AnimDoubleRad.java +++ b/src/mightypork/utils/control/timing/animation/AnimDoubleRad.java @@ -1,4 +1,4 @@ -package mightypork.utils.time.animation; +package mightypork.utils.control.timing.animation; import mightypork.utils.math.Calc; diff --git a/src/mightypork/utils/math/coord/CoordAnimated.java b/src/mightypork/utils/math/coord/CoordAnimated.java index 0d809a6..af66b23 100644 --- a/src/mightypork/utils/math/coord/CoordAnimated.java +++ b/src/mightypork/utils/math/coord/CoordAnimated.java @@ -1,8 +1,8 @@ package mightypork.utils.math.coord; +import mightypork.utils.control.timing.Updateable; import mightypork.utils.math.Calc; -import mightypork.utils.time.Updateable; /** diff --git a/src/mightypork/utils/math/coord/Rect.java b/src/mightypork/utils/math/coord/Rect.java index 26c2cd1..37cf9e3 100644 --- a/src/mightypork/utils/math/coord/Rect.java +++ b/src/mightypork/utils/math/coord/Rect.java @@ -223,7 +223,7 @@ public class Rect { */ public Rect getAxisV() { - return new Rect(getCenterDown(), getCenterTop()); + return new Rect(getCenterBottom(), getCenterTop()); } @@ -243,7 +243,7 @@ public class Rect { * * @return center */ - public Coord getCenterDown() + public Coord getCenterBottom() { return new Coord((max.x + min.x) / 2, min.y); } @@ -353,7 +353,7 @@ public class Rect { */ public Coord getMax() { - return max; + return getRightTop(); } @@ -362,7 +362,7 @@ public class Rect { */ public Coord getOrigin() { - return min; + return getLeftBottom(); } @@ -400,155 +400,171 @@ public class Rect { /** - * Grow to sides in copy + * Shrink to sides in copy * - * @param grow grow size (added to each side) - * @return grown copy + * @param shrink shrink size (added to each side) + * @return shrinkn copy */ - public Rect grow(Coord grow) + public Rect shrink(Coord shrink) { - return copy().grow_ip(grow); + return copy().shrink_ip(shrink); } /** - * Grow to sides in copy + * Shrink to sides in copy * * @param x x to add * @param y y to add - * @return grown copy + * @return changed copy */ - public Rect grow(double x, double y) + public Rect shrink(double x, double y) { - return copy().grow_ip(x, y); + return copy().shrink_ip(x, y); } /** - * Grow to sides in place + * Shrink to sides in place * - * @param grow grow size (added to each side) + * @param shrink shrink size (added to each side) * @return this */ - public Rect grow_ip(Coord grow) + public Rect shrink_ip(Coord shrink) { - min.sub_ip(grow); - max.add_ip(grow); + shrink_ip(shrink.x, shrink.y); return this; } /** - * Grow to sides in place + * Shrink to sides in place * * @param x x to add * @param y y to add * @return this */ - public Rect grow_ip(double x, double y) + public Rect shrink_ip(double x, double y) { min.sub_ip(x, y); - max.add_ip(x, y); + max.add_ip(-x, -y); return this; } /** - * Grow down in copy + * Shrink the rect * - * @param down added pixels - * @return grown copy + * @param left left shrink + * @param top top shrink + * @param right right shrink + * @param bottom bottom shrink + * @return changed copy */ - public Rect growDown(double down) + public Rect shrink(double left, double top, double right, double bottom) { - return copy().growDown_ip(down); + return copy().shrink_ip(left, top, right, bottom); } /** - * Grow down in place + * Shrink the rect in place * - * @param down added pixels + * @param left left shrink + * @param top top shrink + * @param right right shrink + * @param bottom bottom shrink * @return this */ - public Rect growDown_ip(double down) + public Rect shrink_ip(double left, double top, double right, double bottom) { - min.sub_ip(0, down); + min.add_ip(left, bottom); + max.add_ip(-right, -top); return this; } /** - * Grow to left in copy + * Grow to sides in copy * - * @param left added pixels + * @param grow grow size (added to each side) * @return grown copy */ - public Rect growLeft(double left) + public Rect grow(Coord grow) { - return copy().growLeft_ip(left); + return copy().grow_ip(grow); } /** - * Grow to left in place + * Grow to sides in copy * - * @param left added pixels - * @return this + * @param x x to add + * @param y y to add + * @return changed copy */ - public Rect growLeft_ip(double left) + public Rect grow(double x, double y) { - min.sub_ip(left, 0); - return this; + return copy().grow_ip(x, y); } /** - * Grow to right in copy + * Grow to sides in place * - * @param right added pixels - * @return grown copy + * @param grow grow size (added to each side) + * @return this */ - public Rect growRight(double right) + public Rect grow_ip(Coord grow) { - return copy().growRight_ip(right); + grow_ip(grow.x, grow.y); + return this; } /** - * Grow to right in place + * Grow to sides in place * - * @param right added pixels + * @param x x to add + * @param y y to add * @return this */ - public Rect growRight_ip(double right) + public Rect grow_ip(double x, double y) { - max.add_ip(right, 0); + min.sub_ip(x, y); + max.add_ip(x, y); return this; } /** - * Grow up in copy + * Grow the rect * - * @param add added pixels - * @return grown copy + * @param left left growth + * @param top top growth + * @param right right growth + * @param bottom bottom growth + * @return changed copy */ - public Rect growUp(double add) + public Rect grow(double left, double top, double right, double bottom) { - return copy().growUp_ip(add); + return copy().grow_ip(left, top, right, bottom); } /** - * Grow up in place + * Grow the rect in place * - * @param add added pixels + * @param left left growth + * @param top top growth + * @param right right growth + * @param bottom bottom growth * @return this */ - public Rect growUp_ip(double add) + public Rect grow_ip(double left, double top, double right, double bottom) { - max.add_ip(0, add); + min.add_ip(-left, -bottom); + max.add_ip(right, top); return this; } diff --git a/src/mightypork/utils/math/easing/Easing.java b/src/mightypork/utils/math/easing/Easing.java index 332c34a..1bbdd64 100644 --- a/src/mightypork/utils/math/easing/Easing.java +++ b/src/mightypork/utils/math/easing/Easing.java @@ -143,7 +143,7 @@ public abstract class Easing { public static final Easing QUADRATIC_OUT = reverse(QUADRATIC_IN); /** Quadratic (y=t^2) easing both */ - public static final Easing QUADRATIC_IN_OUT = inOut(QUADRATIC_IN); + public static final Easing QUADRATIC_BOTH = inOut(QUADRATIC_IN); /** Cubic (y=t^3) easing in */ public static final Easing CUBIC_IN = new Easing() { @@ -159,7 +159,7 @@ public abstract class Easing { public static final Easing CUBIC_OUT = reverse(CUBIC_IN); /** Cubic (y=t^3) easing both */ - public static final Easing CUBIC_IN_OUT = inOut(CUBIC_IN); + public static final Easing CUBIC_BOTH = inOut(CUBIC_IN); /** Quartic (y=t^4) easing in */ public static final Easing QUARTIC_IN = new Easing() { @@ -175,7 +175,7 @@ public abstract class Easing { public static final Easing QUARTIC_OUT = reverse(QUADRATIC_IN); /** Quartic (y=t^4) easing both */ - public static final Easing QUARTIC_IN_OUT = inOut(QUADRATIC_IN); + public static final Easing QUARTIC_BOTH = inOut(QUADRATIC_IN); /** Quintic (y=t^5) easing in */ public static final Easing QUINTIC_IN = new Easing() { @@ -191,7 +191,7 @@ public abstract class Easing { public static final Easing QUINTIC_OUT = reverse(QUINTIC_IN); /** Quintic (y=t^5) easing both */ - public static final Easing QUINTIC_IN_OUT = inOut(QUINTIC_IN); + public static final Easing QUINTIC_BOTH = inOut(QUINTIC_IN); /** Sine easing in */ public static final Easing SINE_IN = new Easing() { @@ -207,7 +207,7 @@ public abstract class Easing { public static final Easing SINE_OUT = reverse(SINE_IN); /** Sine easing both */ - public static final Easing SINE_IN_OUT = inOut(SINE_IN); + public static final Easing SINE_BOTH = inOut(SINE_IN); /** Exponential easing in */ public static final Easing EXPO_IN = new Easing() { @@ -223,7 +223,7 @@ public abstract class Easing { public static final Easing EXPO_OUT = reverse(EXPO_IN); /** Exponential easing both */ - public static final Easing EXPO_IN_OUT = inOut(EXPO_IN); + public static final Easing EXPO_BOTH = inOut(EXPO_IN); /** Circular easing in */ public static final Easing CIRC_IN = new Easing() { @@ -239,7 +239,7 @@ public abstract class Easing { public static final Easing CIRC_OUT = reverse(CIRC_IN); /** Circular easing both */ - public static final Easing CIRC_IN_OUT = inOut(CIRC_IN); + public static final Easing CIRC_BOTH = inOut(CIRC_IN); /** Bounce easing in */ public static final Easing BOUNCE_OUT = new Easing() { @@ -269,7 +269,7 @@ public abstract class Easing { public static final Easing BOUNCE_IN = reverse(BOUNCE_OUT); /** Bounce easing both */ - public static final Easing BOUNCE_IN_OUT = inOut(BOUNCE_IN); + public static final Easing BOUNCE_BOTH = inOut(BOUNCE_IN); /** Back easing in */ public static final Easing BACK_IN = new Easing() { @@ -286,7 +286,7 @@ public abstract class Easing { public static final Easing BACK_OUT = reverse(BACK_IN); /** Back easing both */ - public static final Easing BACK_IN_OUT = inOut(BACK_IN); + public static final Easing BACK_BOTH = inOut(BACK_IN); /** Elastic easing in */ public static final Easing ELASTIC_IN = new Easing() { @@ -307,5 +307,5 @@ public abstract class Easing { public static final Easing ELASTIC_OUT = reverse(ELASTIC_IN); /** Elastic easing both */ - public static final Easing ELASTIC_IN_OUT = inOut(ELASTIC_IN); + public static final Easing ELASTIC_BOTH = inOut(ELASTIC_IN); }