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