Formatting, classpath.

This commit is contained in:
Ondřej Hruška
2014-04-01 09:07:33 +02:00
parent 4a1a84fd87
commit 4bd18be9bb
106 changed files with 4802 additions and 4043 deletions
+40 -40
View File
@@ -1,6 +1,5 @@
package mightypork.rogue.display;
import static org.lwjgl.opengl.GL11.*;
import java.awt.image.BufferedImage;
@@ -21,31 +20,31 @@ import org.lwjgl.opengl.DisplayMode;
public class DisplaySystem extends DelegatingBusClient implements Bounding {
private DisplayMode windowDisplayMode;
private int targetFps;
public DisplaySystem(AppAccess app) {
super(app, true);
enableUpdates(false);
}
@Override
protected void init()
{
initChannels();
}
@Override
public void deinit()
{
Display.destroy();
}
/**
* Initialize event channels
*/
@@ -53,14 +52,14 @@ public class DisplaySystem extends DelegatingBusClient implements Bounding {
{
bus().createChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class);
}
public void setTargetFps(int fps)
{
this.targetFps = fps;
}
public void createMainWindow(int width, int height, boolean resizable, boolean fullscreen, String title)
{
try {
@@ -69,7 +68,7 @@ public class DisplaySystem extends DelegatingBusClient implements Bounding {
Display.setVSyncEnabled(true);
Display.setTitle(title);
Display.create();
if (fullscreen) {
switchFullscreen();
Display.update();
@@ -78,20 +77,20 @@ public class DisplaySystem extends DelegatingBusClient implements Bounding {
throw new RuntimeException("Could not initialize screen", e);
}
}
/**
* Toggle FS if possible
*/
public void switchFullscreen()
{
try {
if (!Display.isFullscreen()) {
Log.f3("Entering fullscreen.");
// save window resize
windowDisplayMode = new DisplayMode(Display.getWidth(), Display.getHeight());
Display.setDisplayMode(Display.getDesktopDisplayMode());
Display.setFullscreen(true);
Display.update();
@@ -100,9 +99,9 @@ public class DisplaySystem extends DelegatingBusClient implements Bounding {
Display.setDisplayMode(windowDisplayMode);
Display.update();
}
bus().broadcast(new ScreenChangeEvent(true, Display.isFullscreen(), getSize()));
} catch (Throwable t) {
Log.e("Failed to toggle fullscreen mode.", t);
try {
@@ -113,19 +112,20 @@ public class DisplaySystem extends DelegatingBusClient implements Bounding {
}
}
}
public BufferedImage takeScreenshot()
{
glReadBuffer(GL_FRONT);
int width = Display.getDisplayMode().getWidth();
int height = Display.getDisplayMode().getHeight();
int bpp = 4; // Assuming a 32-bit display with a byte each for red, green, blue, and alpha.
int bpp = 4; // Assuming a 32-bit display with a byte each for red,
// green, blue, and alpha.
ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// convert to a buffered image
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
@@ -136,11 +136,11 @@ public class DisplaySystem extends DelegatingBusClient implements Bounding {
image.setRGB(x, height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b);
}
}
return image;
}
/**
* @return true if close was requested (i.e. click on cross)
*/
@@ -148,8 +148,8 @@ public class DisplaySystem extends DelegatingBusClient implements Bounding {
{
return Display.isCloseRequested();
}
/**
* Get fullscreen state
*
@@ -159,8 +159,8 @@ public class DisplaySystem extends DelegatingBusClient implements Bounding {
{
return Display.isFullscreen();
}
/**
* Get screen size
*
@@ -170,8 +170,8 @@ public class DisplaySystem extends DelegatingBusClient implements Bounding {
{
return new Coord(Display.getWidth(), Display.getHeight());
}
/**
* Start a OpenGL frame
*/
@@ -180,12 +180,12 @@ public class DisplaySystem extends DelegatingBusClient implements Bounding {
if (Display.wasResized()) {
bus().broadcast(new ScreenChangeEvent(false, Display.isFullscreen(), getSize()));
}
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
/**
* End an OpenGL frame, flip buffers, sync to fps.
*/
@@ -194,8 +194,8 @@ public class DisplaySystem extends DelegatingBusClient implements Bounding {
Display.update(false); // don't poll input devices
Display.sync(targetFps);
}
@Override
public Rect getRect()
{
+69 -67
View File
@@ -1,6 +1,5 @@
package mightypork.rogue.display;
import static org.lwjgl.opengl.GL11.*;
import mightypork.rogue.AppAccess;
import mightypork.rogue.bus.DelegatingBusClient;
@@ -21,38 +20,39 @@ import mightypork.utils.math.coord.Rect;
* @author MightyPork
*/
public abstract class Screen extends DelegatingBusClient implements KeyBinder, Bounding, ScreenChangeEvent.Listener {
private KeyBindingPool keybindings;
private boolean active;
public Screen(AppAccess app) {
super(app, true);
// disable events initially
enableEvents(false);
}
@Override
public final void bindKeyStroke(KeyStroke stroke, Runnable task)
{
keybindings.bindKeyStroke(stroke, task);
}
@Override
public final void unbindKeyStroke(KeyStroke stroke)
{
keybindings.unbindKeyStroke(stroke);
}
/**
* Prepare for being shown
*
* @param shown true to show, false to hide
* @param shown
* true to show, false to hide
*/
public final void setActive(boolean shown)
{
@@ -62,45 +62,45 @@ public abstract class Screen extends DelegatingBusClient implements KeyBinder, B
setupViewport();
onSizeChanged(getRect().getSize());
onScreenEnter();
// subscribe to event bus
enableEvents(true);
} else {
onScreenLeave();
active = false;
// unsusbcribe from event bus
enableEvents(false);
}
}
private void setupGraphics()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_LIGHTING);
glClearDepth(1f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_NORMALIZE);
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_TEXTURE_2D);
setupViewport();
}
private void setupViewport()
{
// fix projection for changed size
@@ -109,80 +109,82 @@ public abstract class Screen extends DelegatingBusClient implements KeyBinder, B
Coord s = disp().getSize();
glViewport(0, 0, s.xi(), s.yi());
glOrtho(0, s.x, 0, s.y, -1000, 1000);
// back to modelview
glMatrixMode(GL_MODELVIEW);
}
@Override
protected final void init()
{
keybindings = new KeyBindingPool();
addChildSubscriber(keybindings);
initScreen();
}
@Override
protected final void deinit()
{
deinitScreen();
}
/**
* Initialize screen layout and key bindings.<br>
* Called during screen construction.
*/
protected abstract void initScreen();
/**
* Clean up before screen is destroyed.
*/
protected abstract void deinitScreen();
/**
* Called when the screen becomes active
*/
protected abstract void onScreenEnter();
/**
* Called when the screen is no longer active
*/
protected abstract void onScreenLeave();
/**
* Update GUI for new screen size
*
* @param size screen size
* @param size
* screen size
*/
protected void onSizeChanged(Coord size)
{
// no impl
}
/**
* Render screen contents (context is ready for 2D rendering)
*/
protected abstract void renderScreen();
/**
* Update animations and timing
*
* @param delta time elapsed
* @param delta
* time elapsed
*/
protected abstract void updateScreen(double delta);
/**
* Render screen
*/
@@ -191,8 +193,8 @@ public abstract class Screen extends DelegatingBusClient implements KeyBinder, B
glPushAttrib(GL_ENABLE_BIT);
glPushMatrix();
}
/**
* Render screen
*/
@@ -201,8 +203,8 @@ public abstract class Screen extends DelegatingBusClient implements KeyBinder, B
glPopAttrib();
glPopMatrix();
}
/**
* @return true if screen is the curretn screen
*/
@@ -210,19 +212,19 @@ public abstract class Screen extends DelegatingBusClient implements KeyBinder, B
{
return active;
}
@Override
public final void receive(ScreenChangeEvent event)
{
if (!isActive()) return;
setupViewport();
onSizeChanged(event.getScreenSize());
}
/**
* Update and render the screen
*/
@@ -230,17 +232,17 @@ public abstract class Screen extends DelegatingBusClient implements KeyBinder, B
public final void update(double delta)
{
updateScreen(delta);
renderBegin();
renderScreen();
renderEnd();
}
@Override
public final Rect getRect()
{
return disp().getRect();
}
}
@@ -1,6 +1,5 @@
package mightypork.rogue.display;
import java.util.Random;
import mightypork.rogue.AppAccess;
@@ -19,15 +18,15 @@ import org.lwjgl.opengl.Display;
public class ScreenTestAnimations extends Screen implements MouseButtonEvent.Listener {
public ScreenTestAnimations(AppAccess app) {
super(app);
}
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),
@@ -95,12 +94,12 @@ public class ScreenTestAnimations extends Screen implements MouseButtonEvent.Lis
// new AnimDouble(0, Easing.ELASTIC_IN_OUT),
};
//@formatter:on
@Override
public void initScreen()
{
bindKeyStroke(new KeyStroke(Keyboard.KEY_RIGHT), new Runnable() {
@Override
public void run()
{
@@ -109,9 +108,9 @@ public class ScreenTestAnimations extends Screen implements MouseButtonEvent.Lis
}
}
});
bindKeyStroke(new KeyStroke(Keyboard.KEY_LEFT), new Runnable() {
@Override
public void run()
{
@@ -121,40 +120,40 @@ public class ScreenTestAnimations extends Screen implements MouseButtonEvent.Lis
}
});
}
@Override
protected void deinitScreen()
{
// no impl
}
@Override
protected void onScreenEnter()
{
// no impl
}
@Override
protected void onScreenLeave()
{
// no impl
}
@Override
protected void updateScreen(double delta)
{
degAnim.update(delta);
for (AnimDouble a : anims) {
a.update(delta);
}
}
@Override
protected void renderScreen()
{
@@ -163,31 +162,31 @@ public class ScreenTestAnimations extends Screen implements MouseButtonEvent.Lis
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(MouseButtonEvent event)
{
if (event.isDown()) {
Coord vec = disp().getSize().half().vecTo(event.getPos());
Polar p = Polar.fromCoord(vec);
degAnim.fadeTo(p.getAngleDeg() - 90, 1.5);
}
}
}
@@ -1,6 +1,5 @@
package mightypork.rogue.display.constraints;
import mightypork.utils.math.coord.Rect;
@@ -10,7 +9,7 @@ import mightypork.utils.math.coord.Rect;
* @author MightyPork
*/
public interface Bounding {
/**
* @return bounding rectangle
*/
@@ -1,20 +1,19 @@
package mightypork.rogue.display.constraints;
import mightypork.utils.math.coord.Coord;
import mightypork.utils.math.coord.Rect;
public abstract class Constraint implements Bounding {
protected Bounding context;
public Constraint(Bounding context) {
this.context = context;
}
/**
* Assign a context
*
@@ -24,8 +23,8 @@ public abstract class Constraint implements Bounding {
{
this.context = context;
}
/**
* @return context
*/
@@ -33,8 +32,8 @@ public abstract class Constraint implements Bounding {
{
return context;
}
/**
* @return context rect origin
*/
@@ -42,8 +41,8 @@ public abstract class Constraint implements Bounding {
{
return context.getRect().getOrigin();
}
/**
* @return context rect size
*/
@@ -51,9 +50,9 @@ public abstract class Constraint implements Bounding {
{
return context.getRect().getSize();
}
@Override
public abstract Rect getRect();
}
@@ -1,8 +1,7 @@
package mightypork.rogue.display.rendering;
public interface Renderable {
public void render();
}
@@ -1,18 +1,17 @@
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();
}