More easing types, cleanup
This commit is contained in:
@@ -9,10 +9,9 @@ import javax.swing.JOptionPane;
|
||||
|
||||
import mightypork.rogue.display.DisplaySystem;
|
||||
import mightypork.rogue.display.Screen;
|
||||
import mightypork.rogue.display.ScreenSplash;
|
||||
import mightypork.rogue.display.ScreenTestAnimations;
|
||||
import mightypork.rogue.input.InputSystem;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
import mightypork.rogue.input.events.MouseMotionEvent;
|
||||
import mightypork.rogue.sounds.SoundSystem;
|
||||
import mightypork.rogue.tasks.TaskTakeScreenshot;
|
||||
import mightypork.rogue.util.Utils;
|
||||
@@ -24,7 +23,6 @@ import mightypork.utils.time.TimerDelta;
|
||||
import mightypork.utils.time.TimerInterpolating;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
||||
|
||||
public class App implements Destroyable {
|
||||
@@ -273,28 +271,20 @@ public class App implements Destroyable {
|
||||
|
||||
/** timer */
|
||||
private TimerDelta timerRender;
|
||||
private TimerInterpolating timerGui;
|
||||
|
||||
|
||||
private void mainLoop()
|
||||
{
|
||||
screen = new ScreenSplash();
|
||||
screen = new ScreenTestAnimations();
|
||||
|
||||
screen.setActive(true);
|
||||
|
||||
timerRender = new TimerDelta();
|
||||
timerGui = new TimerInterpolating(Const.FPS_GUI_UPDATE);
|
||||
|
||||
while (!display.isCloseRequested()) {
|
||||
display.beginFrame();
|
||||
|
||||
// gui update
|
||||
timerGui.sync();
|
||||
int ticks = timerGui.getSkipped();
|
||||
if (ticks >= 1) {
|
||||
input.poll();
|
||||
timerGui.startNewFrame();
|
||||
}
|
||||
input.poll();
|
||||
|
||||
double delta = timerRender.getDelta();
|
||||
|
||||
|
||||
@@ -6,43 +6,43 @@ import static org.lwjgl.opengl.GL11.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.DisplayMode;
|
||||
|
||||
import mightypork.rogue.App;
|
||||
import mightypork.rogue.Const;
|
||||
import mightypork.rogue.display.events.ScreenChangeEvent;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.patterns.Destroyable;
|
||||
import mightypork.utils.patterns.Initializable;
|
||||
import mightypork.utils.time.Updateable;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.DisplayMode;
|
||||
|
||||
|
||||
public class DisplaySystem implements Initializable, Destroyable {
|
||||
|
||||
private boolean initialized;
|
||||
|
||||
|
||||
private DisplayMode windowDisplayMode;
|
||||
private int targetFps;
|
||||
|
||||
|
||||
|
||||
|
||||
public DisplaySystem() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
if(initialized) return;
|
||||
|
||||
if (initialized) return;
|
||||
|
||||
initChannels();
|
||||
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initialize event channels
|
||||
*/
|
||||
@@ -51,6 +51,7 @@ public class DisplaySystem implements Initializable, Destroyable {
|
||||
App.msgbus().registerMessageType(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
@@ -103,7 +104,7 @@ public class DisplaySystem implements Initializable, Destroyable {
|
||||
Display.setDisplayMode(windowDisplayMode);
|
||||
Display.update();
|
||||
}
|
||||
|
||||
|
||||
App.broadcast(new ScreenChangeEvent(true, Display.isFullscreen(), getSize()));
|
||||
|
||||
} catch (Throwable t) {
|
||||
@@ -180,10 +181,10 @@ public class DisplaySystem implements Initializable, Destroyable {
|
||||
*/
|
||||
public void beginFrame()
|
||||
{
|
||||
if(Display.wasResized()) {
|
||||
if (Display.wasResized()) {
|
||||
App.broadcast(new ScreenChangeEvent(false, Display.isFullscreen(), getSize()));
|
||||
}
|
||||
|
||||
|
||||
glLoadIdentity();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
@@ -2,19 +2,15 @@ package mightypork.rogue.display;
|
||||
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.rogue.App;
|
||||
import mightypork.rogue.display.events.ScreenChangeEvent;
|
||||
import mightypork.rogue.input.KeyBinder;
|
||||
import mightypork.rogue.input.KeyBindingPool;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
import mightypork.rogue.input.events.KeyboardEvent;
|
||||
import mightypork.rogue.input.events.MouseMotionEvent;
|
||||
import mightypork.rogue.input.events.MouseButtonEvent;
|
||||
import mightypork.rogue.input.events.MouseMotionEvent;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.patterns.Destroyable;
|
||||
import mightypork.utils.patterns.Initializable;
|
||||
import mightypork.utils.time.Updateable;
|
||||
|
||||
@@ -54,6 +50,7 @@ public abstract class Screen implements KeyBinder, Updateable, Initializable, Ke
|
||||
|
||||
/**
|
||||
* Prepare for being shown
|
||||
*
|
||||
* @param shown true to show, false to hide
|
||||
*/
|
||||
public final void setActive(boolean shown)
|
||||
@@ -110,14 +107,16 @@ public abstract class Screen implements KeyBinder, Updateable, Initializable, Ke
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initialize screen layout and key bindings.<br>
|
||||
* Called when the screen is created, not when it comes to front. For that, use onEnter().
|
||||
* Called when the screen is created, not when it comes to front. For that,
|
||||
* use onEnter().
|
||||
*/
|
||||
@Override
|
||||
public abstract void initialize();
|
||||
|
||||
|
||||
/**
|
||||
* Called when the screen becomes active
|
||||
*/
|
||||
@@ -172,6 +171,9 @@ public abstract class Screen implements KeyBinder, Updateable, Initializable, Ke
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update and render the screen
|
||||
*/
|
||||
@Override
|
||||
public final void update(double delta)
|
||||
{
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
package mightypork.rogue.display;
|
||||
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
||||
import mightypork.rogue.App;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
import mightypork.rogue.input.events.MouseButtonEvent;
|
||||
import mightypork.rogue.input.events.MouseMotionEvent;
|
||||
import mightypork.rogue.util.RenderUtils;
|
||||
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.AnimDouble;
|
||||
import mightypork.utils.time.AnimDoubleDeg;
|
||||
|
||||
|
||||
public class ScreenSplash extends Screen {
|
||||
|
||||
private AnimDoubleDeg degAnim = new AnimDoubleDeg(0, Easing.SINE);
|
||||
|
||||
//@formatter:off
|
||||
private AnimDouble[] anims = new AnimDouble[] {
|
||||
new AnimDouble(0, Easing.NONE),
|
||||
new AnimDouble(0, Easing.LINEAR),
|
||||
|
||||
new AnimDouble(0, Easing.QUADRATIC_IN),
|
||||
new AnimDouble(0, Easing.QUADRATIC_OUT),
|
||||
new AnimDouble(0, Easing.QUADRATIC),
|
||||
|
||||
new AnimDouble(0, Easing.CUBIC_IN),
|
||||
new AnimDouble(0, Easing.CUBIC_OUT),
|
||||
new AnimDouble(0, Easing.CUBIC),
|
||||
|
||||
new AnimDouble(0, Easing.QUADRATIC_IN),
|
||||
new AnimDouble(0, Easing.QUADRATIC_OUT),
|
||||
new AnimDouble(0, Easing.QUADRATIC),
|
||||
|
||||
new AnimDouble(0, Easing.QUINTIC_IN),
|
||||
new AnimDouble(0, Easing.QUINTIC_OUT),
|
||||
new AnimDouble(0, Easing.QUINTIC_IN_OUT),
|
||||
|
||||
new AnimDouble(0, Easing.EXPO_IN),
|
||||
new AnimDouble(0, Easing.EXPO_OUT),
|
||||
new AnimDouble(0, Easing.EXPO),
|
||||
|
||||
new AnimDouble(0, Easing.SINE_IN),
|
||||
new AnimDouble(0, Easing.SINE_OUT),
|
||||
new AnimDouble(0, Easing.SINE),
|
||||
|
||||
new AnimDouble(0, Easing.CIRC_IN),
|
||||
new AnimDouble(0, Easing.CIRC_OUT),
|
||||
new AnimDouble(0, Easing.CIRC),
|
||||
};
|
||||
//@formatter:on
|
||||
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
bindKeyStroke(new KeyStroke(Keyboard.KEY_RIGHT), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
for (AnimDouble a : anims) {
|
||||
a.animate(0, 1, 3);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bindKeyStroke(new KeyStroke(Keyboard.KEY_LEFT), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
for (AnimDouble a : anims) {
|
||||
a.animate(1, 0, 3);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void renderScreen()
|
||||
{
|
||||
double screenH = Display.getHeight();
|
||||
double screenW = Display.getWidth();
|
||||
double perBoxH = screenH / anims.length;
|
||||
double padding = perBoxH*0.1;
|
||||
double boxSide = perBoxH-padding*2;
|
||||
|
||||
for (int i = 0; i < anims.length; i++) {
|
||||
AnimDouble a = anims[i];
|
||||
|
||||
RenderUtils.setColor(i%3==0?RGB.GREEN:RGB.BLUE);
|
||||
RenderUtils.quadSize(
|
||||
padding + a.getCurrentValue() * (screenW - perBoxH - padding*2),
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(MouseMotionEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(MouseButtonEvent event)
|
||||
{
|
||||
if(event.isDown()) {
|
||||
Coord vec = App.disp().getSize().half().vecTo(event.getPos());
|
||||
|
||||
Polar p = Polar.fromCoord(vec);
|
||||
|
||||
degAnim.fadeTo(p.getAngleDeg() - 90, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onEnter()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onLeave()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(Coord size)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void updateScreen(double delta)
|
||||
{
|
||||
degAnim.update(delta);
|
||||
|
||||
for (AnimDouble a : anims) {
|
||||
a.update(delta);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
package mightypork.rogue.display;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.rogue.App;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
import mightypork.rogue.input.events.MouseButtonEvent;
|
||||
import mightypork.rogue.input.events.MouseMotionEvent;
|
||||
import mightypork.rogue.util.RenderUtils;
|
||||
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;
|
||||
|
||||
|
||||
public class ScreenTestAnimations extends Screen {
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
private AnimDoubleDeg degAnim = new AnimDoubleDeg(0, Easing.ELASTIC_OUT);
|
||||
|
||||
//@formatter:off
|
||||
private AnimDouble[] anims = new AnimDouble[] {
|
||||
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.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.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.BOUNCE_OUT),
|
||||
new AnimDouble(0, Easing.BOUNCE_OUT),
|
||||
|
||||
// new AnimDouble(0, Easing.NONE),
|
||||
// new AnimDouble(0, Easing.LINEAR),
|
||||
//
|
||||
// new AnimDouble(0, Easing.QUADRATIC_IN),
|
||||
// new AnimDouble(0, Easing.QUADRATIC_OUT),
|
||||
// new AnimDouble(0, Easing.QUADRATIC_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.CUBIC_IN),
|
||||
// new AnimDouble(0, Easing.CUBIC_OUT),
|
||||
// new AnimDouble(0, Easing.CUBIC_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.QUADRATIC_IN),
|
||||
// new AnimDouble(0, Easing.QUADRATIC_OUT),
|
||||
// new AnimDouble(0, Easing.QUADRATIC_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.QUINTIC_IN),
|
||||
// new AnimDouble(0, Easing.QUINTIC_OUT),
|
||||
// new AnimDouble(0, Easing.QUINTIC_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.EXPO_IN),
|
||||
// new AnimDouble(0, Easing.EXPO_OUT),
|
||||
// new AnimDouble(0, Easing.EXPO_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.SINE_IN),
|
||||
// new AnimDouble(0, Easing.SINE_OUT),
|
||||
// new AnimDouble(0, Easing.SINE_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.CIRC_IN),
|
||||
// new AnimDouble(0, Easing.CIRC_OUT),
|
||||
// new AnimDouble(0, Easing.CIRC_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.BOUNCE_IN),
|
||||
// new AnimDouble(0, Easing.BOUNCE_OUT),
|
||||
// new AnimDouble(0, Easing.BOUNCE_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.BACK_IN),
|
||||
// new AnimDouble(0, Easing.BACK_OUT),
|
||||
// new AnimDouble(0, Easing.BACK_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.ELASTIC_IN),
|
||||
// new AnimDouble(0, Easing.ELASTIC_OUT),
|
||||
// new AnimDouble(0, Easing.ELASTIC_IN_OUT),
|
||||
};
|
||||
//@formatter:on
|
||||
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
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 renderScreen()
|
||||
{
|
||||
double screenH = Display.getHeight();
|
||||
double screenW = Display.getWidth();
|
||||
double perBoxH = screenH / anims.length;
|
||||
double padding = perBoxH * 0.1;
|
||||
double boxSide = perBoxH - padding * 2;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
RenderUtils.setColor(RGB.YELLOW);
|
||||
RenderUtils.translate(new Coord(Display.getWidth() / 2, Display.getHeight() / 2));
|
||||
RenderUtils.rotateZ(degAnim.getCurrentValue());
|
||||
RenderUtils.quadSize(-10, -10, 20, 200);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(MouseMotionEvent event)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(MouseButtonEvent event)
|
||||
{
|
||||
if (event.isDown()) {
|
||||
Coord vec = App.disp().getSize().half().vecTo(event.getPos());
|
||||
|
||||
Polar p = Polar.fromCoord(vec);
|
||||
|
||||
degAnim.fadeTo(p.getAngleDeg() - 90, 1.5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onEnter()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onLeave()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(Coord size)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void updateScreen(double delta)
|
||||
{
|
||||
degAnim.update(delta);
|
||||
|
||||
for (AnimDouble a : anims) {
|
||||
a.update(delta);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.rogue.display.constraints;
|
||||
|
||||
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
|
||||
@@ -11,9 +12,10 @@ public abstract class Constraint implements ConstraintContext {
|
||||
public Constraint(ConstraintContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public void setContext(ConstraintContext context) {
|
||||
|
||||
|
||||
public void setContext(ConstraintContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@@ -22,12 +24,16 @@ public abstract class Constraint implements ConstraintContext {
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
||||
protected Coord origin() {
|
||||
|
||||
|
||||
protected Coord origin()
|
||||
{
|
||||
return context.getRect().getOrigin();
|
||||
}
|
||||
|
||||
protected Coord size() {
|
||||
|
||||
|
||||
protected Coord size()
|
||||
{
|
||||
return context.getRect().getSize();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package mightypork.rogue.display.constraints;
|
||||
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
public interface ConstraintContext {
|
||||
|
||||
public Rect getRect();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import mightypork.rogue.input.events.MouseMotionEvent;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.patterns.Destroyable;
|
||||
import mightypork.utils.patterns.Initializable;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -112,7 +113,7 @@ public class InputSystem implements KeyBinder, Destroyable, Initializable {
|
||||
int wheeld = Mouse.getEventDWheel();
|
||||
|
||||
if (button != -1 || wheeld != 0) App.broadcast(new MouseButtonEvent(pos, button, down, wheeld));
|
||||
if(!move.isZero()) App.broadcast(new MouseMotionEvent(pos, move));
|
||||
if (!move.isZero()) App.broadcast(new MouseMotionEvent(pos, move));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ public interface KeyBinder {
|
||||
|
||||
/**
|
||||
* Remove handler from a keystroke (id any)
|
||||
*
|
||||
* @param stroke stroke
|
||||
*/
|
||||
abstract void unbindKeyStroke(KeyStroke stroke);
|
||||
|
||||
@@ -14,7 +14,7 @@ public class KeyBinding implements KeyboardEvent.Listener {
|
||||
public KeyBinding(KeyStroke stroke, Runnable handler) {
|
||||
this.keystroke = stroke;
|
||||
this.handler = handler;
|
||||
|
||||
|
||||
wasActive = keystroke.isActive();
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@ public class KeyBinding implements KeyboardEvent.Listener {
|
||||
public void receive(KeyboardEvent event)
|
||||
{
|
||||
// ignore unrelated events
|
||||
if(!keystroke.getKeys().contains(event.getKey())) return;
|
||||
if (!keystroke.getKeys().contains(event.getKey())) return;
|
||||
|
||||
// run handler when event was met
|
||||
if (keystroke.isActive() && !wasActive) {
|
||||
handler.run();
|
||||
}
|
||||
|
||||
|
||||
wasActive = keystroke.isActive();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener {
|
||||
{
|
||||
for (KeyBinding kb : bindings) {
|
||||
if (kb.matches(stroke)) {
|
||||
Log.w("Duplicate KeyBinding ("+stroke+"), using newest handler.");
|
||||
Log.w("Duplicate KeyBinding (" + stroke + "), using newest handler.");
|
||||
kb.setHandler(task);
|
||||
return;
|
||||
}
|
||||
@@ -42,6 +42,7 @@ public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener {
|
||||
|
||||
/**
|
||||
* Remove handler from keystroke (id any)
|
||||
*
|
||||
* @param stroke stroke
|
||||
*/
|
||||
@Override
|
||||
@@ -58,11 +59,12 @@ public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(KeyboardEvent event)
|
||||
{
|
||||
for(KeyBinding kb: bindings) {
|
||||
kb.receive(event);
|
||||
for (KeyBinding kb : bindings) {
|
||||
kb.receive(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package mightypork.rogue.input.events;
|
||||
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import mightypork.utils.patterns.subscription.Handleable;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
|
||||
/**
|
||||
* A keyboard event
|
||||
@@ -41,7 +41,8 @@ public class KeyboardEvent implements Handleable<KeyboardEvent.Listener> {
|
||||
{
|
||||
return down;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return true if key was just released
|
||||
*/
|
||||
@@ -75,11 +76,12 @@ public class KeyboardEvent implements Handleable<KeyboardEvent.Listener> {
|
||||
*/
|
||||
public void receive(KeyboardEvent event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return Keyboard.getKeyName(key)+":"+(down?"DOWN":"UP");
|
||||
return Keyboard.getKeyName(key) + ":" + (down ? "DOWN" : "UP");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import mightypork.utils.objects.Mutable;
|
||||
|
||||
|
||||
public abstract class BaseAudioPlayer {
|
||||
|
||||
|
||||
/** the track */
|
||||
private AudioX audio;
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ package mightypork.rogue.sounds;
|
||||
|
||||
|
||||
import mightypork.utils.objects.Mutable;
|
||||
import mightypork.utils.time.AnimDouble;
|
||||
import mightypork.utils.time.Pauseable;
|
||||
import mightypork.utils.time.Updateable;
|
||||
import mightypork.utils.time.animation.AnimDouble;
|
||||
|
||||
import org.lwjgl.openal.AL10;
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ public class SoundSystem implements Updateable, Destroyable {
|
||||
|
||||
private static Coord listener = new Coord();
|
||||
|
||||
|
||||
static {
|
||||
// initialize sound system
|
||||
SoundStore.get().setMaxSources(MAX_SOURCES);
|
||||
@@ -114,18 +113,19 @@ public class SoundSystem implements Updateable, Destroyable {
|
||||
p.setFadeTimes(fadeIn, fadeOut);
|
||||
loops.put(key, p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create {@link AudioX} for a resource
|
||||
*
|
||||
* @param res a resource name
|
||||
* @return the resource
|
||||
*
|
||||
* @throws IllegalArgumentException if resource is already registered
|
||||
*/
|
||||
private AudioX getResource(String res) {
|
||||
private AudioX getResource(String res)
|
||||
{
|
||||
AudioX a = new AudioX(res);
|
||||
if(resources.contains(a)) throw new IllegalArgumentException("Sound resource "+res+" is already registered.");
|
||||
if (resources.contains(a)) throw new IllegalArgumentException("Sound resource " + res + " is already registered.");
|
||||
resources.add(a);
|
||||
return a;
|
||||
}
|
||||
@@ -298,10 +298,10 @@ public class SoundSystem implements Updateable, Destroyable {
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
for(AudioX r: resources) {
|
||||
for (AudioX r : resources) {
|
||||
r.destroy();
|
||||
}
|
||||
|
||||
|
||||
SoundStore.get().clear();
|
||||
AL.destroy();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ package mightypork.rogue.util;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import mightypork.rogue.textures.TextureManager;
|
||||
import mightypork.rogue.textures.TxQuad;
|
||||
import mightypork.utils.math.Calc.Deg;
|
||||
import mightypork.utils.math.color.HSV;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
@@ -7,7 +7,9 @@ package mightypork.rogue.util;
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class Utils {
|
||||
public static Thread runAsThread(Runnable r) {
|
||||
|
||||
public static Thread runAsThread(Runnable r)
|
||||
{
|
||||
Thread t = new Thread(r);
|
||||
t.start();
|
||||
return t;
|
||||
|
||||
Reference in New Issue
Block a user