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.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);
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,5 +141,4 @@ public class TextPainter extends SimplePainter {
|
||||
{
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ public class App extends BaseApp {
|
||||
{
|
||||
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 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();
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
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 {
|
||||
|
||||
private final NumVar cache = Num.makeVar();
|
||||
@@ -10,6 +21,7 @@ public class NumCache extends NumAdapter {
|
||||
|
||||
public NumCache(Num source) {
|
||||
this.source = source;
|
||||
enableDigestCaching(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
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 {
|
||||
|
||||
private final RectVar cache = Rect.makeVar();
|
||||
@@ -10,6 +21,7 @@ public class RectCache extends RectAdapter {
|
||||
|
||||
public RectCache(Rect source) {
|
||||
this.source = source;
|
||||
enableDigestCaching(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
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 {
|
||||
|
||||
private final VectVar cache = Vect.makeVar();
|
||||
@@ -10,6 +21,7 @@ public class VectCache extends VectAdapter {
|
||||
|
||||
public VectCache(Vect source) {
|
||||
this.source = source;
|
||||
enableDigestCaching(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user