good except 1 mysterious NPE in SimplePainter on poll.
This commit is contained in:
@@ -11,6 +11,7 @@ import mightypork.gamecore.audio.SoundSystem;
|
|||||||
import mightypork.gamecore.control.bus.EventBus;
|
import mightypork.gamecore.control.bus.EventBus;
|
||||||
import mightypork.gamecore.control.bus.events.*;
|
import mightypork.gamecore.control.bus.events.*;
|
||||||
import mightypork.gamecore.control.interf.Destroyable;
|
import mightypork.gamecore.control.interf.Destroyable;
|
||||||
|
import mightypork.gamecore.control.timing.Pollable;
|
||||||
import mightypork.gamecore.control.timing.Updateable;
|
import mightypork.gamecore.control.timing.Updateable;
|
||||||
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
||||||
import mightypork.gamecore.input.InputSystem;
|
import mightypork.gamecore.input.InputSystem;
|
||||||
@@ -255,6 +256,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
|||||||
// framework events
|
// framework events
|
||||||
bus.addChannel(DestroyEvent.class, Destroyable.class);
|
bus.addChannel(DestroyEvent.class, Destroyable.class);
|
||||||
bus.addChannel(UpdateEvent.class, Updateable.class);
|
bus.addChannel(UpdateEvent.class, Updateable.class);
|
||||||
|
bus.addChannel(LayoutChangeEvent.class, Pollable.class);
|
||||||
|
|
||||||
// input events
|
// input events
|
||||||
bus.addChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class);
|
bus.addChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class);
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package mightypork.gamecore.gui.components;
|
package mightypork.gamecore.gui.components;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.utils.annotations.DefaultImpl;
|
||||||
import mightypork.utils.math.constraints.rect.Rect;
|
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.RectBound;
|
||||||
import mightypork.utils.math.constraints.rect.RectBoundAdapter;
|
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
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public abstract class SimplePainter extends RectBoundAdapter implements PluggableRenderable {
|
public abstract class SimplePainter extends RectAdapter implements PluggableRenderable {
|
||||||
|
|
||||||
@Override
|
private RectCache source;
|
||||||
public abstract void render();
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -27,6 +29,41 @@ public abstract class SimplePainter extends RectBoundAdapter implements Pluggabl
|
|||||||
@Override
|
@Override
|
||||||
public void setRect(RectBound rect)
|
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()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,5 +141,4 @@ public class TextPainter extends SimplePainter {
|
|||||||
{
|
{
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package mightypork.gamecore.gui.screens;
|
|||||||
|
|
||||||
import mightypork.gamecore.control.AppAccess;
|
import mightypork.gamecore.control.AppAccess;
|
||||||
import mightypork.gamecore.control.AppSubModule;
|
import mightypork.gamecore.control.AppSubModule;
|
||||||
|
import mightypork.gamecore.control.bus.events.LayoutChangeEvent;
|
||||||
import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
||||||
import mightypork.gamecore.gui.components.Renderable;
|
import mightypork.gamecore.gui.components.Renderable;
|
||||||
import mightypork.gamecore.input.KeyBinder;
|
import mightypork.gamecore.input.KeyBinder;
|
||||||
@@ -99,6 +100,9 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
|
|||||||
|
|
||||||
onSizeChanged(event.getScreenSize());
|
onSizeChanged(event.getScreenSize());
|
||||||
|
|
||||||
|
// poll constraints
|
||||||
|
getEventBus().sendDirectToChildren(this, new LayoutChangeEvent());
|
||||||
|
|
||||||
needSetupViewport = true;
|
needSetupViewport = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class App extends BaseApp {
|
|||||||
{
|
{
|
||||||
bus.addChannel(ActionRequest.class, ActionRequest.Listener.class);
|
bus.addChannel(ActionRequest.class, ActionRequest.Listener.class);
|
||||||
|
|
||||||
//bus.detailedLogging = true;
|
bus.detailedLogging = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package mightypork.rogue.screens.test_bouncyboxes;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
|
||||||
import mightypork.gamecore.control.timing.Updateable;
|
import mightypork.gamecore.control.timing.Updateable;
|
||||||
import mightypork.gamecore.gui.components.SimplePainter;
|
import mightypork.gamecore.gui.components.SimplePainter;
|
||||||
import mightypork.gamecore.render.Render;
|
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.Num;
|
||||||
import mightypork.utils.math.constraints.num.NumAnimated;
|
import mightypork.utils.math.constraints.num.NumAnimated;
|
||||||
import mightypork.utils.math.constraints.rect.Rect;
|
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 Random rand = new Random();
|
||||||
|
|
||||||
private final Rect box;
|
private final RectCache box;
|
||||||
|
|
||||||
private final NumAnimated pos = new NumAnimated(0, Easing.BOUNCE_OUT);
|
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.move(width().sub(height()).mul(pos), Num.ZERO);
|
||||||
abox = abox.shrink(height().perc(10));
|
abox = abox.shrink(height().perc(10));
|
||||||
|
|
||||||
box = abox;
|
box = abox.cached();
|
||||||
box.enableDigestCaching(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,7 +64,7 @@ public class BouncyBox extends SimplePainter implements Updateable, ScreenChange
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receive(ScreenChangeEvent event)
|
public void onPoll()
|
||||||
{
|
{
|
||||||
box.poll();
|
box.poll();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
package mightypork.test;
|
package mightypork.test;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.utils.math.constraints.vect.Vect;
|
import mightypork.utils.math.constraints.vect.Vect;
|
||||||
import mightypork.utils.math.constraints.vect.VectCache;
|
import mightypork.utils.math.constraints.vect.VectCache;
|
||||||
import mightypork.utils.math.constraints.vect.VectVar;
|
import mightypork.utils.math.constraints.vect.VectVar;
|
||||||
|
|
||||||
|
|
||||||
public class TestConstCaching {
|
public class TestConstCaching {
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
VectVar in = Vect.makeVar(0, 0);
|
final VectVar in = Vect.makeVar(0, 0);
|
||||||
VectCache cache = in.cached();
|
final VectCache cache = in.cached();
|
||||||
cache.enableDigestCaching(true);
|
cache.enableDigestCaching(true);
|
||||||
|
|
||||||
System.out.println("in = " + in);
|
System.out.println("in = " + in);
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
package mightypork.utils.math.constraints.num;
|
package mightypork.utils.math.constraints.num;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* A num cache.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Values are held in a caching VectVar, and digest caching is enabled by
|
||||||
|
* default.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author MightyPork
|
||||||
|
*/
|
||||||
public class NumCache extends NumAdapter {
|
public class NumCache extends NumAdapter {
|
||||||
|
|
||||||
private final NumVar cache = Num.makeVar();
|
private final NumVar cache = Num.makeVar();
|
||||||
@@ -10,6 +21,7 @@ public class NumCache extends NumAdapter {
|
|||||||
|
|
||||||
public NumCache(Num source) {
|
public NumCache(Num source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
enableDigestCaching(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
package mightypork.utils.math.constraints.rect;
|
package mightypork.utils.math.constraints.rect;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* A rect cache.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Values are held in a caching VectVar, and digest caching is enabled by
|
||||||
|
* default.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author MightyPork
|
||||||
|
*/
|
||||||
public class RectCache extends RectAdapter {
|
public class RectCache extends RectAdapter {
|
||||||
|
|
||||||
private final RectVar cache = Rect.makeVar();
|
private final RectVar cache = Rect.makeVar();
|
||||||
@@ -10,6 +21,7 @@ public class RectCache extends RectAdapter {
|
|||||||
|
|
||||||
public RectCache(Rect source) {
|
public RectCache(Rect source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
enableDigestCaching(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
package mightypork.utils.math.constraints.vect;
|
package mightypork.utils.math.constraints.vect;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* A vect cache.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Values are held in a caching VectVar, and digest caching is enabled by
|
||||||
|
* default.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author MightyPork
|
||||||
|
*/
|
||||||
public class VectCache extends VectAdapter {
|
public class VectCache extends VectAdapter {
|
||||||
|
|
||||||
private final VectVar cache = Vect.makeVar();
|
private final VectVar cache = Vect.makeVar();
|
||||||
@@ -10,6 +21,7 @@ public class VectCache extends VectAdapter {
|
|||||||
|
|
||||||
public VectCache(Vect source) {
|
public VectCache(Vect source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
enableDigestCaching(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user