Refactoring of subsystems and eventbus
This commit is contained in:
@@ -7,9 +7,9 @@ import java.awt.image.BufferedImage;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import mightypork.rogue.AppAccess;
|
||||
import mightypork.rogue.AppSubsystem;
|
||||
import mightypork.rogue.display.constraints.ConstraintContext;
|
||||
import mightypork.rogue.display.events.ScreenChangeEvent;
|
||||
import mightypork.rogue.bus.DelegatingBusClient;
|
||||
import mightypork.rogue.bus.events.ScreenChangeEvent;
|
||||
import mightypork.rogue.display.constraints.Bounding;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
@@ -20,7 +20,7 @@ import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.DisplayMode;
|
||||
|
||||
|
||||
public class DisplaySystem extends AppSubsystem implements ConstraintContext {
|
||||
public class DisplaySystem extends DelegatingBusClient implements Bounding {
|
||||
|
||||
private DisplayMode windowDisplayMode;
|
||||
private int targetFps;
|
||||
@@ -51,7 +51,7 @@ public class DisplaySystem extends AppSubsystem implements ConstraintContext {
|
||||
*/
|
||||
private void initChannels()
|
||||
{
|
||||
msgbus().createChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class);
|
||||
bus().createChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class DisplaySystem extends AppSubsystem implements ConstraintContext {
|
||||
Display.update();
|
||||
}
|
||||
|
||||
msgbus().broadcast(new ScreenChangeEvent(true, Display.isFullscreen(), getSize()));
|
||||
bus().broadcast(new ScreenChangeEvent(true, Display.isFullscreen(), getSize()));
|
||||
|
||||
} catch (Throwable t) {
|
||||
Log.e("Failed to toggle fullscreen mode.", t);
|
||||
@@ -178,7 +178,7 @@ public class DisplaySystem extends AppSubsystem implements ConstraintContext {
|
||||
public void beginFrame()
|
||||
{
|
||||
if (Display.wasResized()) {
|
||||
msgbus().broadcast(new ScreenChangeEvent(false, Display.isFullscreen(), getSize()));
|
||||
bus().broadcast(new ScreenChangeEvent(false, Display.isFullscreen(), getSize()));
|
||||
}
|
||||
|
||||
glLoadIdentity();
|
||||
|
||||
@@ -3,9 +3,9 @@ package mightypork.rogue.display;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import mightypork.rogue.AppAccess;
|
||||
import mightypork.rogue.AppSubsystem;
|
||||
import mightypork.rogue.display.constraints.ConstraintContext;
|
||||
import mightypork.rogue.display.events.ScreenChangeEvent;
|
||||
import mightypork.rogue.bus.DelegatingBusClient;
|
||||
import mightypork.rogue.bus.events.ScreenChangeEvent;
|
||||
import mightypork.rogue.display.constraints.Bounding;
|
||||
import mightypork.rogue.input.KeyBinder;
|
||||
import mightypork.rogue.input.KeyBindingPool;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
@@ -20,7 +20,7 @@ import mightypork.utils.math.coord.Rect;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public abstract class Screen extends AppSubsystem implements KeyBinder, ConstraintContext, ScreenChangeEvent.Listener {
|
||||
public abstract class Screen extends DelegatingBusClient implements KeyBinder, Bounding, ScreenChangeEvent.Listener {
|
||||
|
||||
private KeyBindingPool keybindings;
|
||||
|
||||
@@ -28,7 +28,10 @@ public abstract class Screen extends AppSubsystem implements KeyBinder, Constrai
|
||||
|
||||
|
||||
public Screen(AppAccess app) {
|
||||
super(app, false);
|
||||
super(app, true);
|
||||
|
||||
// disable events initially
|
||||
enableEvents(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ package mightypork.rogue.display;
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.rogue.AppAccess;
|
||||
import mightypork.rogue.bus.events.MouseButtonEvent;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
import mightypork.rogue.input.events.MouseButtonEvent;
|
||||
import mightypork.rogue.util.RenderUtils;
|
||||
import mightypork.utils.math.Polar;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
|
||||
+2
-2
@@ -5,11 +5,11 @@ import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
/**
|
||||
* Constraints can be based on this
|
||||
* Bounding box provider - context for {@link Constraint}
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface ConstraintContext {
|
||||
public interface Bounding {
|
||||
|
||||
/**
|
||||
* @return bounding rectangle
|
||||
@@ -2,39 +2,58 @@ package mightypork.rogue.display.constraints;
|
||||
|
||||
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
public abstract class Constraint implements ConstraintContext {
|
||||
public abstract class Constraint implements Bounding {
|
||||
|
||||
protected ConstraintContext context;
|
||||
protected Bounding context;
|
||||
|
||||
|
||||
public Constraint(ConstraintContext context) {
|
||||
public Constraint(Bounding context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public void setContext(ConstraintContext context)
|
||||
/**
|
||||
* Assign a context
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void setContext(Bounding context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public ConstraintContext getContext()
|
||||
/**
|
||||
* @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();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
package mightypork.rogue.display.events;
|
||||
|
||||
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.patterns.subscription.Handleable;
|
||||
|
||||
|
||||
public class ScreenChangeEvent implements Handleable<ScreenChangeEvent.Listener> {
|
||||
|
||||
private boolean fullscreen;
|
||||
private Coord screenSize;
|
||||
private boolean fsChanged;
|
||||
|
||||
|
||||
public ScreenChangeEvent(boolean fsChanged, boolean fullscreen, Coord size) {
|
||||
this.fullscreen = fullscreen;
|
||||
this.screenSize = size;
|
||||
this.fsChanged = fsChanged;
|
||||
}
|
||||
|
||||
|
||||
public boolean isFullscreen()
|
||||
{
|
||||
return fullscreen;
|
||||
}
|
||||
|
||||
|
||||
public boolean fullscreenChanged()
|
||||
{
|
||||
return fsChanged;
|
||||
}
|
||||
|
||||
|
||||
public Coord getScreenSize()
|
||||
{
|
||||
return screenSize;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleBy(Listener handler)
|
||||
{
|
||||
handler.receive(this);
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
|
||||
public void receive(ScreenChangeEvent event);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package mightypork.rogue.display.events;
|
||||
|
||||
|
||||
import mightypork.utils.patterns.subscription.Handleable;
|
||||
|
||||
|
||||
public class UpdateEvent implements Handleable<UpdateEvent.Listener> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package mightypork.rogue.display.rendering;
|
||||
|
||||
|
||||
public interface Renderable {
|
||||
|
||||
public void render();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package mightypork.rogue.display.rendering;
|
||||
|
||||
|
||||
import mightypork.rogue.AppAccess;
|
||||
import mightypork.rogue.bus.DelegatingBusClient;
|
||||
|
||||
|
||||
public abstract class ScreenLayer extends DelegatingBusClient implements Renderable {
|
||||
|
||||
public ScreenLayer(AppAccess app) {
|
||||
super(app, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public abstract void render();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user