A lot of performance improvements

This commit is contained in:
Andrea Cavalli 2017-09-15 23:24:12 +02:00
parent 70adfc81b6
commit 30512b143d
27 changed files with 226 additions and 31 deletions

View File

@ -6,7 +6,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>

1
.gitignore vendored
View File

@ -10,6 +10,7 @@
/target/
/backups/
/Resources_and_Videos/
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

View File

@ -1,6 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter

Binary file not shown.

View File

@ -1,6 +1,7 @@
package org.warp.picalculator.gui;
import java.io.IOException;
import java.util.concurrent.Semaphore;
import org.warp.picalculator.Main;
import org.warp.picalculator.Utils;
@ -234,6 +235,13 @@ public final class DisplayManager implements RenderingLoop {
}
private void draw_init() {
if (engine.supportsFontRegistering()) {
for (BinaryFont f : engine.getRegisteredFonts()) {
if (!f.isInitialized()) {
f.initialize(engine);
}
}
}
renderer.glClear(engine.getWidth(), engine.getHeight());
}
@ -375,11 +383,12 @@ public final class DisplayManager implements RenderingLoop {
public void loop() {
try {
load_skin();
load_fonts();
engine.create();
renderer = engine.getRenderer();
load_skin();
load_fonts();
try {
screen.initialize();
} catch (final Exception e) {

View File

@ -1,6 +1,7 @@
package org.warp.picalculator.gui.graphicengine;
import java.io.IOException;
import java.util.ArrayList;
public interface GraphicEngine {
@ -15,6 +16,8 @@ public interface GraphicEngine {
public void setDisplayMode(final int ww, final int wh);
public void create();
public void create(Runnable object);
public boolean wasResized();
@ -39,4 +42,8 @@ public interface GraphicEngine {
public boolean isSupported();
public boolean doesRefreshPauses();
public boolean supportsFontRegistering();
public ArrayList<BinaryFont> getRegisteredFonts();
}

View File

@ -7,6 +7,8 @@ public interface Skin {
public void load(String file) throws IOException;
public void initialize(GraphicEngine d);
public boolean isInitialized();
public void use(GraphicEngine d);
}

View File

@ -4,6 +4,7 @@ import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
@ -45,14 +46,21 @@ public class CPUEngine implements GraphicEngine {
g = new BufferedImage(ww, wh, BufferedImage.TYPE_INT_ARGB);
INSTANCE.wasResized = false;
}
@Override
public void create() {
create(null);
}
@Override
public void create(Runnable onInitialized) {
INSTANCE = new SwingWindow(this);
setResizable(Utils.debugOn & !Utils.debugThirdScreen);
setDisplayMode(Main.screenSize[0], Main.screenSize[1]);
INSTANCE.setVisible(true);
initialized = true;
if (onInitialized != null)
onInitialized.run();
}
@Override
@ -185,4 +193,16 @@ public class CPUEngine implements GraphicEngine {
public boolean doesRefreshPauses() {
return true;
}
@Override
public boolean supportsFontRegistering() {
// TODO Auto-generated method stub
return false;
}
@Override
public ArrayList<BinaryFont> getRegisteredFonts() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -149,8 +149,6 @@ public class CPUFont implements BinaryFont {
@Override
public void initialize(GraphicEngine d) {
// TODO Auto-generated method stub
}
@Override
@ -178,4 +176,9 @@ public class CPUFont implements BinaryFont {
return charH;
}
@Override
public boolean isInitialized() {
return true;
}
}

View File

@ -48,4 +48,9 @@ public class CPUSkin implements Skin {
((CPURenderer) d.getRenderer()).currentSkin = this;
}
@Override
public boolean isInitialized() {
return true;
}
}

View File

@ -1,10 +1,12 @@
package org.warp.picalculator.gui.graphicengine.gpu;
import java.io.IOException;
import java.util.ArrayList;
import org.warp.picalculator.Main;
import org.warp.picalculator.Utils;
import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.Skin;
@ -18,6 +20,7 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
private RenderingLoop d;
private GPURenderer r;
int[] size = new int[] { Main.screenSize[0], Main.screenSize[1] };
private final ArrayList<BinaryFont> registeredFonts = new ArrayList<BinaryFont>();
@Override
public int[] getSize() {
@ -53,6 +56,11 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
@Override
public void create() {
create(null);
}
@Override
public void create(Runnable onInitialized) {
created = true;
r = new GPURenderer();
wnd = new NEWTWindow(this);
@ -60,6 +68,7 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
setDisplayMode(Main.screenSize[0], Main.screenSize[1]);
setResizable(Utils.debugOn & !Utils.debugThirdScreen);
initialized = true;
wnd.onInitialized = onInitialized;
}
@Override
@ -104,12 +113,12 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
@Override
public BinaryFont loadFont(String file) throws IOException {
return new GPUFont(file);
return new GPUFont(this, file);
}
@Override
public Skin loadSkin(String file) throws IOException {
return new GPUSkin(file);
return new GPUSkin(this, file);
}
@Override
@ -145,5 +154,19 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
public boolean doesRefreshPauses() {
return false;
}
public void registerFont(GPUFont gpuFont) {
registeredFonts.add(gpuFont);
}
@Override
public boolean supportsFontRegistering() {
return true;
}
@Override
public ArrayList<BinaryFont> getRegisteredFonts() {
return registeredFonts;
}
}

View File

@ -25,10 +25,11 @@ public class GPUFont implements BinaryFont {
public int memoryWidthOfEachColumn;
private boolean initialized = false;
private CPUFont tmpFont;
private BufferedImage tmpFont;
GPUFont(String file) throws IOException {
GPUFont(GraphicEngine g, String file) throws IOException {
load(file);
((GPUEngine) g).registerFont(this);
}
@Override
@ -38,7 +39,7 @@ public class GPUFont implements BinaryFont {
charH = font.charH;
minCharIndex = font.minBound;
maxCharIndex = font.maxBound;
tmpFont = font;
pregenTexture(font.rawchars);
font = null;
}
@ -56,7 +57,7 @@ public class GPUFont implements BinaryFont {
return (ch & 0xFFFF) - minCharIndex;
}
private void genTexture(boolean[][] chars) {
private void pregenTexture(boolean[][] chars) {
final double totalChars = maxCharIndex - minCharIndex;
final int w = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charW)));
final int h = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charH)));
@ -86,11 +87,17 @@ public class GPUFont implements BinaryFont {
memoryWidth = w;
memoryHeight = h;
memoryWidthOfEachColumn = maxIndexW;
texture = GPURenderer.importTexture(bfi);
textureW = bfi.getWidth();
textureH = bfi.getHeight();
bfi.flush();
bfi = null;
this.tmpFont = bfi;
} catch (GLException e) {
e.printStackTrace();
}
}
private void genTexture() {
try {
texture = GPURenderer.importTexture(tmpFont);
} catch (GLException | IOException e) {
e.printStackTrace();
}
@ -102,9 +109,7 @@ public class GPUFont implements BinaryFont {
@Override
public void initialize(GraphicEngine d) {
genTexture(tmpFont.rawchars);
tmpFont.chars32 = null;
tmpFont.rawchars = null;
genTexture();
tmpFont = null;
initialized = true;
}
@ -138,4 +143,9 @@ public class GPUFont implements BinaryFont {
public int getCharacterHeight() {
return charH;
}
@Override
public boolean isInitialized() {
return initialized;
}
}

View File

@ -3,6 +3,7 @@ package org.warp.picalculator.gui.graphicengine.gpu;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

View File

@ -20,7 +20,7 @@ public class GPUSkin implements Skin {
private String texturePath;
private boolean initialized = false;
GPUSkin(String file) throws IOException {
GPUSkin(GraphicEngine d, String file) throws IOException {
load(file);
}
@ -57,4 +57,9 @@ public class GPUSkin implements Skin {
r.useTexture(t, w, h);
}
@Override
public boolean isInitialized() {
return initialized;
}
}

View File

@ -60,6 +60,7 @@ class NEWTWindow implements GLEventListener {
private final GPUEngine disp;
private final GPURenderer renderer;
public Runnable onInitialized;
public NEWTWindow(GPUEngine disp) {
this.disp = disp;
@ -279,7 +280,7 @@ class NEWTWindow implements GLEventListener {
@Override
public void init(GLAutoDrawable drawable) {
final GL2ES1 gl = drawable.getGL().getGL2ES1();
//Vsync
gl.setSwapInterval(2);
@ -291,6 +292,10 @@ class NEWTWindow implements GLEventListener {
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glShadeModel(GLLightingFunc.GL_FLAT);
if (onInitialized != null) {
onInitialized.run();
onInitialized = null;
}
try {
renderer.currentTex = ((GPUSkin) disp.loadSkin("test.png")).t;
} catch (final Exception e) {
@ -330,7 +335,7 @@ class NEWTWindow implements GLEventListener {
@Override
public void display(GLAutoDrawable glad) {
final GL2ES1 gl = glad.getGL().getGL2ES1();
GPURenderer.gl = gl;
gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);

View File

@ -6,6 +6,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.logging.ConsoleHandler;
import org.fusesource.jansi.AnsiConsole;
@ -16,6 +17,7 @@ import org.warp.picalculator.Main;
import org.warp.picalculator.Utils;
import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
@ -64,6 +66,11 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
@Override
public void create() {
this.create(null);
}
@Override
public void create(Runnable onInitialized) {
Utils.outputLevel = -1;
AnsiConsole.systemInstall();
if(Utils.isWindows() && !Utils.msDosMode){
@ -134,6 +141,8 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
t.start();
}
stopped = false;
if (onInitialized != null)
onInitialized.run();
}
@Override
@ -321,4 +330,14 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
public boolean doesRefreshPauses() {
return true;
}
@Override
public boolean supportsFontRegistering() {
return false;
}
@Override
public ArrayList<BinaryFont> getRegisteredFonts() {
return null;
}
}

View File

@ -39,4 +39,9 @@ public class Headless24bitFont implements BinaryFont {
return 5;
}
@Override
public boolean isInitialized() {
return true;
}
}

View File

@ -57,5 +57,10 @@ public class Headless24bitSkin implements Skin {
((Headless24bitRenderer) d.getRenderer()).currentSkin = this;
}
@Override
public boolean isInitialized() {
return true;
}
}

View File

@ -1,6 +1,7 @@
package org.warp.picalculator.gui.graphicengine.headless256;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.ConsoleHandler;
import org.fusesource.jansi.AnsiConsole;
@ -9,6 +10,7 @@ import org.warp.picalculator.Main;
import org.warp.picalculator.Utils;
import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer;
@ -56,6 +58,11 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
@Override
public void create() {
this.create(null);
}
@Override
public void create(Runnable onInitialized) {
Utils.outputLevel = -1;
AnsiConsole.systemInstall();
if(Utils.isWindows() && !Utils.msDosMode){
@ -126,6 +133,8 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
t.start();
}
stopped = false;
if (onInitialized != null)
onInitialized.run();
}
@Override
@ -271,4 +280,16 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
public boolean doesRefreshPauses() {
return true;
}
@Override
public boolean supportsFontRegistering() {
// TODO Auto-generated method stub
return false;
}
@Override
public ArrayList<BinaryFont> getRegisteredFonts() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -39,4 +39,9 @@ public class Headless256Font implements BinaryFont {
return 5;
}
@Override
public boolean isInitialized() {
return true;
}
}

View File

@ -61,5 +61,10 @@ public class Headless256Skin implements Skin {
((Headless256Renderer) d.getRenderer()).currentSkin = this;
}
@Override
public boolean isInitialized() {
return true;
}
}

View File

@ -1,6 +1,7 @@
package org.warp.picalculator.gui.graphicengine.headless8;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.ConsoleHandler;
import org.fusesource.jansi.AnsiConsole;
@ -9,6 +10,8 @@ import org.warp.picalculator.Main;
import org.warp.picalculator.Utils;
import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer;
@ -56,6 +59,11 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
@Override
public void create() {
this.create(null);
}
@Override
public void create(Runnable onInitialized) {
Utils.outputLevel = -1;
AnsiConsole.systemInstall();
if(Utils.isWindows() && !Utils.msDosMode){
@ -126,6 +134,8 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
t.start();
}
stopped = false;
if (onInitialized != null)
onInitialized.run();
}
@Override
@ -271,4 +281,16 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
public boolean doesRefreshPauses() {
return true;
}
@Override
public boolean supportsFontRegistering() {
// TODO Auto-generated method stub
return false;
}
@Override
public ArrayList<BinaryFont> getRegisteredFonts() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -39,4 +39,9 @@ public class Headless8Font implements BinaryFont {
return 5;
}
@Override
public boolean isInitialized() {
return true;
}
}

View File

@ -56,5 +56,10 @@ public class Headless8Skin implements Skin {
((Headless8Renderer) d.getRenderer()).currentSkin = this;
}
@Override
public boolean isInitialized() {
return true;
}
}

View File

@ -60,7 +60,8 @@ public class Division extends FunctionOperator {
if (((Number) variable1).isInteger() && ((Number) variable2).isInteger()) {
LinkedList<BigInteger> factors1 = ((Number) variable1).getFactors();
LinkedList<BigInteger> factors2 = ((Number) variable2).getFactors();
return factors1.retainAll(factors2) /* True If something changed in the factors list by keeping only the intersection of the two factor lists */ && factors1.size() > 0 /* true if there is at least one common factor */;
factors1.retainAll(factors2);
return factors1.size() > 0 /* true if there is at least one common factor */;
} else if (((Number) variable1).divide((Number) variable2).isInteger()) {
return true;
} else {
@ -99,15 +100,14 @@ public class Division extends FunctionOperator {
if (getMathContext().exactMode && (((Number) variable1).isInteger() && ((Number) variable2).isInteger())) {
LinkedList<BigInteger> factors1 = ((Number) variable1).getFactors();
LinkedList<BigInteger> factors2 = ((Number) variable2).getFactors();
if(factors1.retainAll(factors2)) { //True If something changed in the factors list by keeping only the intersection of the two factor lists.
BigInteger nmb1 = ((Number) this.getParameter1()).term.toBigIntegerExact();
BigInteger nmb2 = ((Number) this.getParameter2()).term.toBigIntegerExact();
for (BigInteger i : factors1) {
nmb1 = nmb1.divide(i);
nmb2 = nmb2.divide(i);
}
result.add(new Division(mathContext, new Number(mathContext, nmb1), new Number(mathContext, nmb2)));
factors1.retainAll(factors2);
BigInteger nmb1 = ((Number) this.getParameter1()).term.toBigIntegerExact();
BigInteger nmb2 = ((Number) this.getParameter2()).term.toBigIntegerExact();
for (BigInteger i : factors1) {
nmb1 = nmb1.divide(i);
nmb2 = nmb2.divide(i);
}
result.add(new Division(mathContext, new Number(mathContext, nmb1), new Number(mathContext, nmb2)));
} else {
result.add(((Number) variable1).divide((Number) variable2));
}

View File

@ -75,10 +75,13 @@ public class Number implements Function {
public Number pow(Number f) throws Error {
Number ret = new Number(root, BigDecimal.ONE);
if (Utils.isIntegerValue(f.term)) {
final BigInteger bi = f.term.toBigInteger();
final BigInteger bi = f.term.toBigInteger().abs();
for (BigInteger i = BigInteger.ZERO; i.compareTo(bi) < 0; i = i.add(BigInteger.ONE)) {
ret = ret.multiply(new Number(root, getTerm()));
}
if (f.term.signum() == -1) {
ret = new Number(root, 1).divide(ret);
}
} else {
ret.term = BigDecimalMath.pow(term, f.term);
}

1
src/main/resources/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/Thumbs.db