Merge branch 'retina-display'
commit
513ee106f1
|
|
@ -48,6 +48,7 @@ public class AppHelper implements Runnable{
|
|||
//one of us...
|
||||
if(obj instanceof BasicApp) {
|
||||
apps.add((BasicApp)(obj));
|
||||
((BasicApp)obj).initialize();
|
||||
}
|
||||
progress++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,12 +72,6 @@ public abstract interface BasicApp {
|
|||
*/
|
||||
public abstract Color getColor();
|
||||
|
||||
/**
|
||||
* the framerate that this should be run at.
|
||||
* @return
|
||||
*/
|
||||
public abstract int getFramerate();
|
||||
|
||||
/**
|
||||
* should this window be resizable
|
||||
* @return
|
||||
|
|
|
|||
|
|
@ -21,6 +21,13 @@ import javax.swing.*;
|
|||
|
||||
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
|
||||
*/
|
||||
|
|
@ -42,16 +49,6 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
*/
|
||||
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
|
||||
* COVERED.
|
||||
|
|
@ -216,6 +213,8 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
|
||||
frame.setVisible(true);
|
||||
|
||||
long nanos = System.nanoTime();
|
||||
|
||||
// now we do stuff.
|
||||
while (running) {
|
||||
// FPS STUFF WORRY NOT, ITS ALL GOOD. MOVE ALONG.
|
||||
|
|
@ -227,21 +226,13 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
}
|
||||
framesInCurrentSecond++;
|
||||
|
||||
// tick stuff
|
||||
tick();
|
||||
// paint the same stuff
|
||||
repaint();
|
||||
|
||||
// FRAMERATE OVERCLOCKING AND SUCH, MOVE ALONG.
|
||||
try {
|
||||
if (!overclock)
|
||||
Thread.sleep((long) Math.floor(sleepTime - (System.currentTimeMillis() - startTime)));
|
||||
else
|
||||
Thread.sleep(0);
|
||||
lag = false;
|
||||
} catch (Exception e) {
|
||||
lag = true;
|
||||
}
|
||||
tick();
|
||||
tickTime = (System.nanoTime() - nanos)/1000d;
|
||||
deltaTime = tickTime * timeScale;
|
||||
nanos = System.nanoTime();
|
||||
|
||||
//no sleeping because we now operate on delta time.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -302,7 +293,7 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
* @param 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 resizable
|
||||
*/
|
||||
private static void setWindowProperties(Dimension dimension, int fps, boolean resizable) {
|
||||
private static void setWindowProperties(Dimension dimension, boolean resizable) {
|
||||
frame.setResizable(resizable);
|
||||
staticMain.setSize(dimension);
|
||||
frame.pack();
|
||||
frame.setLocationRelativeTo(null);
|
||||
WIDTH = dimension.width;
|
||||
HEIGHT = dimension.height;
|
||||
setFramerate(fps);
|
||||
frame.setResizable(resizable);
|
||||
|
||||
}
|
||||
|
|
@ -354,8 +344,6 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
// show fps if debug level high enough
|
||||
if (debug > 0)
|
||||
g.drawString("FPS: " + FPS, 20, 20);
|
||||
if (overclock)
|
||||
g.drawString("Overclocking!", 20, 35);
|
||||
g.setColor(Color.RED);
|
||||
if (lag)
|
||||
g.fillOval(10, 10, 10, 10);
|
||||
|
|
@ -382,9 +370,7 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
apps[app].keyPressed(e);
|
||||
if (e.getKeyCode() == KeyEvent.VK_O && keys[KeyEvent.VK_CONTROL]) {
|
||||
overclock = !overclock;
|
||||
}
|
||||
|
||||
keys[e.getKeyCode()] = true;
|
||||
}
|
||||
|
||||
|
|
@ -403,11 +389,6 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
System.exit(0);
|
||||
}
|
||||
|
||||
private static void setFramerate(int fps) {
|
||||
frameSync = fps;
|
||||
sleepTime = 1000 / frameSync;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
updateMouse(e);
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ public class ImageCreator {
|
|||
double power = width > height ? width : height;
|
||||
power *= 2;
|
||||
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 double SEED = 1000.0;
|
||||
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 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++) {
|
||||
|
|
@ -162,10 +165,35 @@ public class ImageCreator {
|
|||
BufferedImage _return = new BufferedImage(width, height, BufferedImage.TRANSLUCENT);
|
||||
_return.getGraphics().drawImage(img, 0 - (img.getWidth() / 8), 0 - (img.getHeight() / 8), null);
|
||||
return _return;
|
||||
|
||||
}
|
||||
|
||||
private static double log(double b, double x) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue