diff --git a/src/mightypork/gamecore/control/BaseApp.java b/src/mightypork/gamecore/control/BaseApp.java index 1de2808..848cf2f 100644 --- a/src/mightypork/gamecore/control/BaseApp.java +++ b/src/mightypork/gamecore/control/BaseApp.java @@ -11,6 +11,7 @@ import mightypork.gamecore.audio.SoundSystem; import mightypork.gamecore.control.bus.EventBus; import mightypork.gamecore.control.bus.events.*; import mightypork.gamecore.control.interf.Destroyable; +import mightypork.gamecore.control.timing.Pollable; import mightypork.gamecore.control.timing.Updateable; import mightypork.gamecore.gui.screens.ScreenRegistry; import mightypork.gamecore.input.InputSystem; @@ -255,6 +256,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler { // framework events bus.addChannel(DestroyEvent.class, Destroyable.class); bus.addChannel(UpdateEvent.class, Updateable.class); + bus.addChannel(LayoutChangeEvent.class, Pollable.class); // input events bus.addChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class); diff --git a/src/mightypork/gamecore/gui/components/SimplePainter.java b/src/mightypork/gamecore/gui/components/SimplePainter.java index d44a761..b6451f7 100644 --- a/src/mightypork/gamecore/gui/components/SimplePainter.java +++ b/src/mightypork/gamecore/gui/components/SimplePainter.java @@ -1,9 +1,12 @@ package mightypork.gamecore.gui.components; +import mightypork.utils.annotations.DefaultImpl; import mightypork.utils.math.constraints.rect.Rect; +import mightypork.utils.math.constraints.rect.RectAdapter; import mightypork.utils.math.constraints.rect.RectBound; import mightypork.utils.math.constraints.rect.RectBoundAdapter; +import mightypork.utils.math.constraints.rect.RectCache; /** @@ -11,10 +14,9 @@ import mightypork.utils.math.constraints.rect.RectBoundAdapter; * * @author MightyPork */ -public abstract class SimplePainter extends RectBoundAdapter implements PluggableRenderable { +public abstract class SimplePainter extends RectAdapter implements PluggableRenderable { - @Override - public abstract void render(); + private RectCache source; @Override @@ -27,6 +29,41 @@ public abstract class SimplePainter extends RectBoundAdapter implements Pluggabl @Override public void setRect(RectBound rect) { - super.setRect(rect); + System.out.println("SP set rect"); + this.source = new RectBoundAdapter(rect).cached(); + } + + + @Override + protected Rect getSource() + { + return source; + } + + + /** + * Poll bounds + */ + @Override + public final void poll() + { + System.out.println("SP poll, source: "+source); + source.poll(); + super.poll(); + + onPoll(); + } + + + @Override + public abstract void render(); + + + /** + * Called after painter was polled; contained constraints can now poll too. + */ + @DefaultImpl + public void onPoll() + { } } diff --git a/src/mightypork/gamecore/gui/components/painters/TextPainter.java b/src/mightypork/gamecore/gui/components/painters/TextPainter.java index 668e64b..0b0f18c 100644 --- a/src/mightypork/gamecore/gui/components/painters/TextPainter.java +++ b/src/mightypork/gamecore/gui/components/painters/TextPainter.java @@ -141,5 +141,4 @@ public class TextPainter extends SimplePainter { { this.text = text; } - } diff --git a/src/mightypork/gamecore/gui/screens/Screen.java b/src/mightypork/gamecore/gui/screens/Screen.java index c3fdcc6..9f87948 100644 --- a/src/mightypork/gamecore/gui/screens/Screen.java +++ b/src/mightypork/gamecore/gui/screens/Screen.java @@ -3,6 +3,7 @@ package mightypork.gamecore.gui.screens; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppSubModule; +import mightypork.gamecore.control.bus.events.LayoutChangeEvent; import mightypork.gamecore.control.bus.events.ScreenChangeEvent; import mightypork.gamecore.gui.components.Renderable; import mightypork.gamecore.input.KeyBinder; @@ -99,6 +100,9 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind onSizeChanged(event.getScreenSize()); + // poll constraints + getEventBus().sendDirectToChildren(this, new LayoutChangeEvent()); + needSetupViewport = true; } diff --git a/src/mightypork/rogue/App.java b/src/mightypork/rogue/App.java index bd6a5ba..a38fbfe 100644 --- a/src/mightypork/rogue/App.java +++ b/src/mightypork/rogue/App.java @@ -100,7 +100,7 @@ public class App extends BaseApp { { bus.addChannel(ActionRequest.class, ActionRequest.Listener.class); - //bus.detailedLogging = true; + bus.detailedLogging = true; } diff --git a/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java b/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java index 2fe23f9..c76cd1b 100644 --- a/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java +++ b/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java @@ -3,7 +3,6 @@ package mightypork.rogue.screens.test_bouncyboxes; import java.util.Random; -import mightypork.gamecore.control.bus.events.ScreenChangeEvent; import mightypork.gamecore.control.timing.Updateable; import mightypork.gamecore.gui.components.SimplePainter; import mightypork.gamecore.render.Render; @@ -12,13 +11,14 @@ import mightypork.utils.math.color.RGB; import mightypork.utils.math.constraints.num.Num; import mightypork.utils.math.constraints.num.NumAnimated; import mightypork.utils.math.constraints.rect.Rect; +import mightypork.utils.math.constraints.rect.RectCache; -public class BouncyBox extends SimplePainter implements Updateable, ScreenChangeEvent.Listener { +public class BouncyBox extends SimplePainter implements Updateable { private final Random rand = new Random(); - private final Rect box; + private final RectCache box; private final NumAnimated pos = new NumAnimated(0, Easing.BOUNCE_OUT); @@ -30,8 +30,7 @@ public class BouncyBox extends SimplePainter implements Updateable, ScreenChange abox = abox.move(width().sub(height()).mul(pos), Num.ZERO); abox = abox.shrink(height().perc(10)); - box = abox; - box.enableDigestCaching(true); + box = abox.cached(); } @@ -65,7 +64,7 @@ public class BouncyBox extends SimplePainter implements Updateable, ScreenChange @Override - public void receive(ScreenChangeEvent event) + public void onPoll() { box.poll(); } diff --git a/src/mightypork/test/TestConstCaching.java b/src/mightypork/test/TestConstCaching.java index 67d4dbd..f6c524e 100644 --- a/src/mightypork/test/TestConstCaching.java +++ b/src/mightypork/test/TestConstCaching.java @@ -1,38 +1,40 @@ package mightypork.test; + import mightypork.utils.math.constraints.vect.Vect; import mightypork.utils.math.constraints.vect.VectCache; import mightypork.utils.math.constraints.vect.VectVar; public class TestConstCaching { + public static void main(String[] args) { - VectVar in = Vect.makeVar(0, 0); - VectCache cache = in.cached(); + final VectVar in = Vect.makeVar(0, 0); + final VectCache cache = in.cached(); cache.enableDigestCaching(true); - - System.out.println("in = "+in); - System.out.println("cache = "+cache); + + System.out.println("in = " + in); + System.out.println("cache = " + cache); System.out.println("cache digest = " + cache.digest()); System.out.println("\n-- in := 100, 50, 25 --\n"); - in.setTo(100,50,25); - System.out.println("in = "+in); - System.out.println("cache = "+cache); + in.setTo(100, 50, 25); + System.out.println("in = " + in); + System.out.println("cache = " + cache); System.out.println("cache digest = " + cache.digest()); System.out.println("\n-- cache.poll() --\n"); cache.poll(); - System.out.println("in = "+in); - System.out.println("cache = "+cache); + System.out.println("in = " + in); + System.out.println("cache = " + cache); System.out.println("cache digest = " + cache.digest()); System.out.println("\n-- in := 1, 2, 3 --\n"); - in.setTo(1,2,3); - System.out.println("in = "+in); - System.out.println("cache = "+cache); + in.setTo(1, 2, 3); + System.out.println("in = " + in); + System.out.println("cache = " + cache); System.out.println("cache digest = " + cache.digest()); System.out.println("\n-- cache.poll() --\n"); cache.poll(); - System.out.println("cache = "+cache); + System.out.println("cache = " + cache); System.out.println("cache digest = " + cache.digest()); } diff --git a/src/mightypork/utils/math/constraints/num/NumCache.java b/src/mightypork/utils/math/constraints/num/NumCache.java index 435a01f..578612b 100644 --- a/src/mightypork/utils/math/constraints/num/NumCache.java +++ b/src/mightypork/utils/math/constraints/num/NumCache.java @@ -1,6 +1,17 @@ package mightypork.utils.math.constraints.num; +/** + *

+ * A num cache. + *

+ *

+ * Values are held in a caching VectVar, and digest caching is enabled by + * default. + *

+ * + * @author MightyPork + */ public class NumCache extends NumAdapter { private final NumVar cache = Num.makeVar(); @@ -10,6 +21,7 @@ public class NumCache extends NumAdapter { public NumCache(Num source) { this.source = source; + enableDigestCaching(true); } diff --git a/src/mightypork/utils/math/constraints/rect/RectCache.java b/src/mightypork/utils/math/constraints/rect/RectCache.java index 83e0f60..b25082b 100644 --- a/src/mightypork/utils/math/constraints/rect/RectCache.java +++ b/src/mightypork/utils/math/constraints/rect/RectCache.java @@ -1,6 +1,17 @@ package mightypork.utils.math.constraints.rect; +/** + *

+ * A rect cache. + *

+ *

+ * Values are held in a caching VectVar, and digest caching is enabled by + * default. + *

+ * + * @author MightyPork + */ public class RectCache extends RectAdapter { private final RectVar cache = Rect.makeVar(); @@ -10,6 +21,7 @@ public class RectCache extends RectAdapter { public RectCache(Rect source) { this.source = source; + enableDigestCaching(true); } diff --git a/src/mightypork/utils/math/constraints/vect/VectCache.java b/src/mightypork/utils/math/constraints/vect/VectCache.java index daa0cd2..a2795f8 100644 --- a/src/mightypork/utils/math/constraints/vect/VectCache.java +++ b/src/mightypork/utils/math/constraints/vect/VectCache.java @@ -1,6 +1,17 @@ package mightypork.utils.math.constraints.vect; +/** + *

+ * A vect cache. + *

+ *

+ * Values are held in a caching VectVar, and digest caching is enabled by + * default. + *

+ * + * @author MightyPork + */ public class VectCache extends VectAdapter { private final VectVar cache = Vect.makeVar(); @@ -10,6 +21,7 @@ public class VectCache extends VectAdapter { public VectCache(Vect source) { this.source = source; + enableDigestCaching(true); }