Reduced rendering time to 0.00102ms (before 0.00148)
This commit is contained in:
parent
2f9d72191f
commit
7d02f51cd5
@ -13,15 +13,13 @@ public class Main {
|
||||
public static final int[] screenSize = new int[] { 480, 320 };
|
||||
public static final int screenScale = 1;
|
||||
public static final boolean zoomed = true;
|
||||
public static PIDisplay d;
|
||||
public static Main instance;
|
||||
|
||||
public Main() throws InterruptedException {
|
||||
instance = this;
|
||||
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
|
||||
beforeStart();
|
||||
d = new PIDisplay(new LoadingScreen());
|
||||
d.run("Raspberry PI Calculator by XDrake99 (Andrea Cavalli)");
|
||||
new PIDisplay(new LoadingScreen());
|
||||
Utils.debug.println("Shutdown...");
|
||||
beforeShutdown();
|
||||
Utils.debug.println("");
|
||||
|
@ -370,8 +370,8 @@ public class Keyboard {
|
||||
}
|
||||
|
||||
public static void keyPressed(Key k) {
|
||||
if (Main.d != null) {
|
||||
Screen scr = Main.d.getScreen();
|
||||
if (PIDisplay.INSTANCE != null) {
|
||||
Screen scr = PIDisplay.INSTANCE.getScreen();
|
||||
boolean refresh = false;
|
||||
if(scr != null && scr.initialized && scr.keyPressed(k)) {
|
||||
refresh = true;
|
||||
@ -454,7 +454,7 @@ public class Keyboard {
|
||||
refresh = true;
|
||||
}
|
||||
if (refresh) {
|
||||
Display.refresh(true);
|
||||
Display.repaint(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -465,8 +465,8 @@ public class Keyboard {
|
||||
|
||||
public static void keyReleased(Key k) {
|
||||
boolean refresh = false;
|
||||
if (Main.d != null) {
|
||||
Screen scr = Main.d.getScreen();
|
||||
if (PIDisplay.INSTANCE != null) {
|
||||
Screen scr = PIDisplay.INSTANCE.getScreen();
|
||||
if(scr != null && scr.initialized && scr.keyReleased(k)) {
|
||||
refresh = true;
|
||||
} else {
|
||||
@ -478,7 +478,7 @@ public class Keyboard {
|
||||
}
|
||||
}
|
||||
if (refresh) {
|
||||
Display.refresh(true);
|
||||
Display.repaint(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ public final class PIDisplay {
|
||||
public PIDisplay(Screen screen) {
|
||||
setScreen(screen);
|
||||
INSTANCE = this;
|
||||
run();
|
||||
}
|
||||
/*
|
||||
* private void load_skin() {
|
||||
@ -91,7 +92,7 @@ public final class PIDisplay {
|
||||
try {
|
||||
screen.create();
|
||||
PIDisplay.screen = screen;
|
||||
if (initialized == true && screen.initialized == false) {
|
||||
if (screen.initialized == false) {
|
||||
screen.initialize();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -307,7 +308,7 @@ public final class PIDisplay {
|
||||
|
||||
private long precTime = -1;
|
||||
|
||||
private void refresh(boolean forced) {
|
||||
public void refresh(boolean forced) {
|
||||
float dt = 0;
|
||||
long newtime = System.nanoTime();
|
||||
if (precTime == -1) {
|
||||
@ -332,36 +333,18 @@ public final class PIDisplay {
|
||||
|
||||
}
|
||||
|
||||
private volatile Startable refresh = new Startable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PIDisplay.this.refresh(this.force);
|
||||
}
|
||||
};
|
||||
|
||||
private void checkDisplayResized() {
|
||||
if (Display.wasResized()) {
|
||||
Main.screenSize[0] = Display.getWidth();
|
||||
Main.screenSize[1]= Display.getHeight();
|
||||
}
|
||||
};
|
||||
|
||||
private void createWindow(String title) {
|
||||
Display.setTitle(title);
|
||||
Display.setResizable(Utils.debugOn);
|
||||
Display.setDisplayMode(Main.screenSize[0], Main.screenSize[1]);
|
||||
Display.create();
|
||||
}
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
public void run(String title) {
|
||||
public void run() {
|
||||
try {
|
||||
createWindow(title);
|
||||
load_skin();
|
||||
load_fonts();
|
||||
|
||||
initialized = true;
|
||||
Display.create();
|
||||
|
||||
try {
|
||||
screen.initialize();
|
||||
@ -370,14 +353,14 @@ public final class PIDisplay {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
Display.start(this.refresh);
|
||||
Display.start();
|
||||
|
||||
Main.instance.afterStart();
|
||||
|
||||
double extratime = 0;
|
||||
while (Display.initialized()) {
|
||||
while (Display.initialized) {
|
||||
long start = System.nanoTime();
|
||||
Display.refresh(false);
|
||||
Display.repaint(false);
|
||||
long end = System.nanoTime();
|
||||
double delta = (end - start) / 1000000000;
|
||||
int deltaInt = (int) Math.floor(delta);
|
||||
|
@ -15,6 +15,7 @@ import java.awt.image.BufferedImage;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
@ -40,6 +41,10 @@ public class PIFrame extends JFrame {
|
||||
// Set the blank cursor to the JFrame.
|
||||
getContentPane().setCursor(blankCursor);
|
||||
}
|
||||
|
||||
this.setTitle("Raspberry PI Calculator by XDrake99 (Andrea Cavalli)");
|
||||
this.setResizable(Utils.debugOn);
|
||||
|
||||
this.addComponentListener(new ComponentListener() {
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
@ -445,11 +450,6 @@ public class PIFrame extends JFrame {
|
||||
super.repaint();
|
||||
}
|
||||
|
||||
private boolean forcerefresh = false;
|
||||
|
||||
public void repaint(boolean force) {
|
||||
forcerefresh = force;
|
||||
super.repaint();
|
||||
}
|
||||
public boolean forcerefresh = false;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
@ -14,10 +15,9 @@ public class Display {
|
||||
private static PIFrame INSTANCE = new PIFrame();
|
||||
public static int[] size = new int[] { 1, 1 };
|
||||
public static BufferedImage g = new BufferedImage(size[0], size[1], BufferedImage.TYPE_INT_ARGB);
|
||||
public static int[] canvas2d = new int[1];
|
||||
private static int[] canvas2d = new int[1];
|
||||
public static int color = 0xFF000000;
|
||||
private static volatile Startable refresh;
|
||||
private static boolean initialized = false;
|
||||
public static boolean initialized = false;
|
||||
|
||||
public static void setTitle(String title) {
|
||||
INSTANCE.setTitle(title);
|
||||
@ -38,13 +38,10 @@ public class Display {
|
||||
}
|
||||
|
||||
public static void create() {
|
||||
Display.setDisplayMode(Main.screenSize[0], Main.screenSize[1]);
|
||||
INSTANCE.setVisible(true);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
public static boolean initialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
public static boolean wasResized() {
|
||||
if (INSTANCE.wasResized) {
|
||||
@ -71,31 +68,42 @@ public class Display {
|
||||
INSTANCE.dispose();
|
||||
}
|
||||
|
||||
public static void start(Startable refresh) {
|
||||
Display.refresh = refresh;
|
||||
public static void start() {
|
||||
}
|
||||
|
||||
@Deprecated()
|
||||
public static void refresh() {
|
||||
if (PIDisplay.screen == null || (PIDisplay.error != null && PIDisplay.error.length() > 0) || PIDisplay.screen == null || PIDisplay.screen.mustBeRefreshed()) {
|
||||
Display.INSTANCE.c.repaint(false);
|
||||
Display.INSTANCE.c.forcerefresh = false;
|
||||
Display.INSTANCE.c.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public static void refresh(boolean force) {
|
||||
Display.INSTANCE.c.repaint(force);
|
||||
public static void repaint(boolean force) {
|
||||
Display.INSTANCE.c.forcerefresh = force;
|
||||
Display.INSTANCE.c.repaint();
|
||||
}
|
||||
|
||||
// private static ArrayList<Double> mediaValori = new ArrayList<Double>();
|
||||
|
||||
public static void update(Graphics g, boolean forcerefresh) {
|
||||
if (refresh != null) {
|
||||
refresh.force = forcerefresh;
|
||||
refresh.run();
|
||||
// long time1 = System.nanoTime();
|
||||
PIDisplay.INSTANCE.refresh(forcerefresh);
|
||||
|
||||
final int[] a = ((DataBufferInt) Display.g.getRaster().getDataBuffer()).getData();
|
||||
System.arraycopy(canvas2d, 0, a, 0, canvas2d.length);
|
||||
g.clearRect(0, 0, size[0], size[1]);
|
||||
g.drawImage(Display.g, 0, 0, null);
|
||||
}
|
||||
final int[] a = ((DataBufferInt) Display.g.getRaster().getDataBuffer()).getData();
|
||||
// System.arraycopy(canvas2d, 0, a, 0, canvas2d.length);
|
||||
canvas2d = a;
|
||||
g.clearRect(0, 0, size[0], size[1]);
|
||||
g.drawImage(Display.g, 0, 0, null);
|
||||
// long time2 = System.nanoTime();
|
||||
// double timeDelta = ((double)(time2-time1))/1000000000d;
|
||||
// double mediaAttuale = timeDelta;
|
||||
// mediaValori.add(mediaAttuale);
|
||||
// double somma = 0;
|
||||
// for (Double val : mediaValori) {
|
||||
// somma+=val;
|
||||
// }
|
||||
// System.out.println(somma/((double)mediaValori.size()));
|
||||
}
|
||||
|
||||
public static abstract class Startable {
|
||||
|
@ -4,6 +4,7 @@ import static org.warp.picalculator.device.graphicengine.Display.Render.*;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
@ -51,11 +52,11 @@ public class SolveEquationScreen extends Screen {
|
||||
public boolean keyPressed(Key k) {
|
||||
switch (k) {
|
||||
case LETTER_X:
|
||||
Main.d.goBack();
|
||||
PIDisplay.INSTANCE.goBack();
|
||||
try {
|
||||
Calculator.solve('X');
|
||||
} catch (Error e) {
|
||||
Screen scr = Main.d.getScreen();
|
||||
Screen scr = PIDisplay.INSTANCE.getScreen();
|
||||
if (scr instanceof EquationScreen) {
|
||||
EquationScreen escr = (EquationScreen) scr;
|
||||
escr.errorLevel = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user