Merge branch 'retina-display'

retina-display^2
Marcus Gosselin 2015-04-05 21:10:44 -04:00
commit 513ee106f1
4 changed files with 50 additions and 46 deletions

View File

@ -48,6 +48,7 @@ public class AppHelper implements Runnable{
//one of us... //one of us...
if(obj instanceof BasicApp) { if(obj instanceof BasicApp) {
apps.add((BasicApp)(obj)); apps.add((BasicApp)(obj));
((BasicApp)obj).initialize();
} }
progress++; progress++;
} }

View File

@ -72,12 +72,6 @@ public abstract interface BasicApp {
*/ */
public abstract Color getColor(); public abstract Color getColor();
/**
* the framerate that this should be run at.
* @return
*/
public abstract int getFramerate();
/** /**
* should this window be resizable * should this window be resizable
* @return * @return

View File

@ -21,6 +21,13 @@ import javax.swing.*;
public class Engine extends Canvas implements KeyListener, MouseMotionListener, MouseListener, ContainerListener, ComponentListener { public class Engine extends Canvas implements KeyListener, MouseMotionListener, MouseListener, ContainerListener, ComponentListener {
/**
*
*/
private static double tickTime = 0;
public static double timeScale = 1;
public static double deltaTime = 0;
/** /**
* to track the x and y * to track the x and y
*/ */
@ -42,16 +49,6 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
*/ */
private static AppHelper appInitializer; private static AppHelper appInitializer;
/**
* AER WE SUPER SPEEDING?!?!?
*/
private static boolean overclock = false;
/**
* current framerate and time required to sleep to achieve that framerate.
*/
private static int frameSync = 50, sleepTime = 1000 / frameSync;
/** /**
* variables to track the fps, DON'T WORRY ABOUT IT, PAST YOU HAS YOU * variables to track the fps, DON'T WORRY ABOUT IT, PAST YOU HAS YOU
* COVERED. * COVERED.
@ -216,6 +213,8 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
frame.setVisible(true); frame.setVisible(true);
long nanos = System.nanoTime();
// now we do stuff. // now we do stuff.
while (running) { while (running) {
// FPS STUFF WORRY NOT, ITS ALL GOOD. MOVE ALONG. // FPS STUFF WORRY NOT, ITS ALL GOOD. MOVE ALONG.
@ -227,21 +226,13 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
} }
framesInCurrentSecond++; framesInCurrentSecond++;
// tick stuff
tick();
// paint the same stuff
repaint(); repaint();
tick();
tickTime = (System.nanoTime() - nanos)/1000d;
deltaTime = tickTime * timeScale;
nanos = System.nanoTime();
// FRAMERATE OVERCLOCKING AND SUCH, MOVE ALONG. //no sleeping because we now operate on delta time.
try {
if (!overclock)
Thread.sleep((long) Math.floor(sleepTime - (System.currentTimeMillis() - startTime)));
else
Thread.sleep(0);
lag = false;
} catch (Exception e) {
lag = true;
}
} }
} }
@ -302,7 +293,7 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
* @param app * @param app
*/ */
private static void setWindowProperties(BasicApp app) { private static void setWindowProperties(BasicApp app) {
setWindowProperties(app.getResolution(), app.getFramerate(), app.getResizable()); setWindowProperties(app.getResolution(), app.getResizable());
} }
/** /**
@ -312,14 +303,13 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
* @param fps * @param fps
* @param resizable * @param resizable
*/ */
private static void setWindowProperties(Dimension dimension, int fps, boolean resizable) { private static void setWindowProperties(Dimension dimension, boolean resizable) {
frame.setResizable(resizable); frame.setResizable(resizable);
staticMain.setSize(dimension); staticMain.setSize(dimension);
frame.pack(); frame.pack();
frame.setLocationRelativeTo(null); frame.setLocationRelativeTo(null);
WIDTH = dimension.width; WIDTH = dimension.width;
HEIGHT = dimension.height; HEIGHT = dimension.height;
setFramerate(fps);
frame.setResizable(resizable); frame.setResizable(resizable);
} }
@ -354,8 +344,6 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
// show fps if debug level high enough // show fps if debug level high enough
if (debug > 0) if (debug > 0)
g.drawString("FPS: " + FPS, 20, 20); g.drawString("FPS: " + FPS, 20, 20);
if (overclock)
g.drawString("Overclocking!", 20, 35);
g.setColor(Color.RED); g.setColor(Color.RED);
if (lag) if (lag)
g.fillOval(10, 10, 10, 10); g.fillOval(10, 10, 10, 10);
@ -382,9 +370,7 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
apps[app].keyPressed(e); apps[app].keyPressed(e);
if (e.getKeyCode() == KeyEvent.VK_O && keys[KeyEvent.VK_CONTROL]) {
overclock = !overclock;
}
keys[e.getKeyCode()] = true; keys[e.getKeyCode()] = true;
} }
@ -403,11 +389,6 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
System.exit(0); System.exit(0);
} }
private static void setFramerate(int fps) {
frameSync = fps;
sleepTime = 1000 / frameSync;
}
@Override @Override
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {
updateMouse(e); updateMouse(e);

View File

@ -99,7 +99,7 @@ public class ImageCreator {
double power = width > height ? width : height; double power = width > height ? width : height;
power *= 2; power *= 2;
power = (int) (log(2, power) + .5); power = (int) (log(2, power) + .5);
//not my code hell if i know how it works //not my code
final int DATA_SIZE = (int) Math.pow(2, power) + 1; final int DATA_SIZE = (int) Math.pow(2, power) + 1;
final double SEED = 1000.0; final double SEED = 1000.0;
double[][] data = new double[DATA_SIZE][DATA_SIZE]; double[][] data = new double[DATA_SIZE][DATA_SIZE];
@ -147,7 +147,10 @@ public class ImageCreator {
} }
for (int i = 0; i < DATA_SIZE; i++) { for (int i = 0; i < DATA_SIZE; i++) {
for (int j = 0; j < DATA_SIZE; j++) { for (int j = 0; j < DATA_SIZE; j++) {
img.setRGB(i, j, (0xFF000000) | ((int) (((data[i][j] - min) / (max - min)) * 255) << 16) | ((int) (((data[i][j] - min) / (max - min)) * 255) << 8) | ((int) (((data[i][j] - min) / (max - min)) * 255))); img.setRGB(i, j, (0xFF000000) |
((int) (((data[i][j] - min) / (max - min)) * 255) << 16) |
((int) (((data[i][j] - min) / (max - min)) * 255) << 8) |
((int) (((data[i][j] - min) / (max - min)) * 255) << 0));
} }
} }
for (int i = 0; i < DATA_SIZE; i++) { for (int i = 0; i < DATA_SIZE; i++) {
@ -162,10 +165,35 @@ public class ImageCreator {
BufferedImage _return = new BufferedImage(width, height, BufferedImage.TRANSLUCENT); BufferedImage _return = new BufferedImage(width, height, BufferedImage.TRANSLUCENT);
_return.getGraphics().drawImage(img, 0 - (img.getWidth() / 8), 0 - (img.getHeight() / 8), null); _return.getGraphics().drawImage(img, 0 - (img.getWidth() / 8), 0 - (img.getHeight() / 8), null);
return _return; return _return;
} }
private static double log(double b, double x) { private static double log(double b, double x) {
return Math.log(x) / Math.log(b); return Math.log(x) / Math.log(b);
} }
public static BufferedImage colorNoise(int r, int g, int b, double multMin,
double multMax, int width, int height) {
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
Graphics graphics = image.getGraphics();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
double k = Math.random() * (multMax - multMin) + multMin;
graphics.setColor(new Color((int) (r * k), (int) (g * k),
(int) (b * k)));
graphics.fillRect(i, j, 1, 1);
}
}
return image;
}
public static Image colorNoise(Color c, double d, double i, int width,
int height) {
return colorNoise(c.getRed(), c.getGreen(), c.getBlue(), d, i, width,
height);
}
} }