From d5b34941bd39c80499cf91234606afe206499c1b Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Thu, 29 Mar 2018 19:20:28 +0200 Subject: [PATCH] Passing directly the FloatBuffer to the GPU Completed the keypad key assignments --- .../java/org/warp/picalculator/TestGPU.java | 4 +- .../org/warp/picalculator/device/Key.java | 12 ++ .../warp/picalculator/device/Keyboard.java | 196 ++++++++++-------- .../device/KeyboardEventListener.java | 2 - .../gui/expression/blocks/BlockVariable.java | 2 +- .../gui/graphicengine/cpu/CPUFont.java | 34 +-- .../gui/graphicengine/gpu/GPUFont.java | 18 +- .../gui/graphicengine/gpu/GPURenderer.java | 32 +-- .../gui/graphicengine/gpu/NEWTWindow.java | 4 +- .../headless24bit/Headless24bitEngine.java | 2 +- .../headless256/Headless256Engine.java | 2 +- .../headless8/Headless8Engine.java | 2 +- .../screens/ChooseVariableValueScreen.java | 2 +- .../picalculator/gui/screens/EmptyScreen.java | 2 +- .../gui/screens/KeyboardDebugScreen.java | 2 +- .../gui/screens/LoadingScreen.java | 2 +- .../picalculator/gui/screens/MarioScreen.java | 2 +- .../gui/screens/MathInputScreen.java | 2 +- ...uationScreen.java => SolveForXScreen.java} | 6 +- 19 files changed, 187 insertions(+), 141 deletions(-) create mode 100644 src/main/java/org/warp/picalculator/device/Key.java rename src/main/java/org/warp/picalculator/gui/screens/{SolveEquationScreen.java => SolveForXScreen.java} (90%) diff --git a/src/main/java/org/warp/picalculator/TestGPU.java b/src/main/java/org/warp/picalculator/TestGPU.java index 9b9fe79e..2d144fd8 100755 --- a/src/main/java/org/warp/picalculator/TestGPU.java +++ b/src/main/java/org/warp/picalculator/TestGPU.java @@ -2,8 +2,8 @@ package org.warp.picalculator; import java.io.IOException; +import org.warp.picalculator.device.Key; import org.warp.picalculator.device.Keyboard; -import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.device.KeyboardEventListener; import org.warp.picalculator.gui.expression.InputContext; import org.warp.picalculator.gui.expression.blocks.BlockContainer; @@ -99,7 +99,7 @@ public class TestGPU { case RESET: c.clear(); return true; - case POWER: + case POWEROFF: d.destroy(); System.exit(0); return true; diff --git a/src/main/java/org/warp/picalculator/device/Key.java b/src/main/java/org/warp/picalculator/device/Key.java new file mode 100644 index 00000000..71238e7c --- /dev/null +++ b/src/main/java/org/warp/picalculator/device/Key.java @@ -0,0 +1,12 @@ +package org.warp.picalculator.device; + +public enum Key { + POWEROFF, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK, + HISTORY_FORWARD, SURD_MODE, DRG_CYCLE, LETTER_X, LETTER_Y, LETTER_Z, STEP, + SIMPLIFY, BRIGHTNESS_CYCLE, BRIGHTNESS_CYCLE_REVERSE, DOT, NUM0, NUM1, NUM2, + NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, PARENTHESIS_OPEN, PARENTHESIS_CLOSE, + PLUS, MINUS, PLUS_MINUS, MULTIPLY, DIVIDE, EQUAL, DELETE, RESET, LEFT, RIGHT, + UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5, SQRT, ROOT, POWER_OF_2, + POWER_OF_x, SINE, COSINE, TANGENT, ARCSINE, ARCCOSINE, ARCTANGENT, PI, SETTINGS, + F1, F2, F3, F4, BACK +} \ No newline at end of file diff --git a/src/main/java/org/warp/picalculator/device/Keyboard.java b/src/main/java/org/warp/picalculator/device/Keyboard.java index 64a648f3..6dad4530 100755 --- a/src/main/java/org/warp/picalculator/device/Keyboard.java +++ b/src/main/java/org/warp/picalculator/device/Keyboard.java @@ -101,7 +101,7 @@ public class Keyboard { private synchronized static void debugKeyPressed(int keyCode) { switch (keyCode) { case KeyEvent.VK_ESCAPE: - Keyboard.keyPressed(Key.POWER); + Keyboard.keyPressed(Key.POWEROFF); break; case KeyEvent.VK_S: if (Keyboard.shift) { @@ -462,76 +462,76 @@ public class Keyboard { {Key.NONE, Key.NONE, Key.NONE}, /* 0,2 */ {Key.NONE, Key.NONE, Key.NONE}, /* 0,3 */ {Key.NONE, Key.NONE, Key.NONE}, /* 0,4 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 0,5 */ + {Key.SETTINGS, Key.NONE, Key.NONE}, /* 0,5 */ {Key.BRIGHTNESS_CYCLE, Key.BRIGHTNESS_CYCLE_REVERSE, Key.NONE}, /* 0,6 */ {Key.SIMPLIFY, Key.STEP, Key.NONE} /* 0,7 */ }, { /* ROW 1 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 1,0 */ + {Key.F4, Key.F4, Key.F4}, /* 1,0 */ {Key.NONE, Key.NONE, Key.NONE}, /* 1,1 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 1,2 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 1,3 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 1,4 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 1,5 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 1,6 */ + {Key.LEFT, Key.NONE, Key.NONE}, /* 1,2 */ + {Key.OK, Key.NONE, Key.NONE}, /* 1,3 */ + {Key.RIGHT, Key.NONE, Key.NONE}, /* 1,4 */ + {Key.HISTORY_BACK, Key.NONE, Key.NONE}, /* 1,5 */ + {Key.HISTORY_FORWARD, Key.NONE, Key.NONE}, /* 1,6 */ {Key.NONE, Key.PI, Key.DRG_CYCLE} /* 1,7 */ }, { /* ROW 2 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 2,0 */ - {Key.SQRT, Key.NONE, Key.LETTER_Y}, /* 2,1 */ + {Key.F3, Key.F4, Key.F4}, /* 2,0 */ + {Key.SQRT, Key.ROOT, Key.NONE}, /* 2,1 */ {Key.NONE, Key.NONE, Key.NONE}, /* 2,2 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 2,3 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 2,4 */ + {Key.DOWN, Key.NONE, Key.NONE}, /* 2,3 */ + {Key.BACK, Key.NONE, Key.NONE}, /* 2,4 */ {Key.NONE, Key.NONE, Key.NONE}, /* 2,5 */ {Key.NONE, Key.NONE, Key.NONE}, /* 2,6 */ - {Key.NONE, Key.NONE, Key.NONE} /* 2,7 */ + {Key.NONE, Key.NONE, Key.LETTER_Z} /* 2,7 */ }, { /* ROW 3 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 3,0 */ + {Key.F2, Key.F2, Key.F2}, /* 3,0 */ {Key.NONE, Key.NONE, Key.NONE}, /* 3,1 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 3,2 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 3,3 */ + {Key.POWER_OF_x, Key.NONE, Key.NONE}, /* 3,2 */ + {Key.POWER_OF_2, Key.NONE, Key.NONE}, /* 3,3 */ {Key.NONE, Key.NONE, Key.NONE}, /* 3,4 */ {Key.NONE, Key.NONE, Key.NONE}, /* 3,5 */ {Key.NONE, Key.NONE, Key.NONE}, /* 3,6 */ - {Key.NONE, Key.NONE, Key.NONE} /* 3,7 */ + {Key.DOT, Key.NONE, Key.LETTER_Y} /* 3,7 */ }, { /* ROW 4 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 4,0 */ + {Key.F1, Key.F1, Key.F1}, /* 4,0 */ {Key.NONE, Key.NONE, Key.NONE}, /* 4,1 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 4,2 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 4,3 */ + {Key.PARENTHESIS_OPEN, Key.NONE, Key.NONE}, /* 4,2 */ + {Key.PARENTHESIS_CLOSE, Key.NONE, Key.NONE}, /* 4,3 */ {Key.NONE, Key.NONE, Key.NONE}, /* 4,4 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 4,5 */ + {Key.SURD_MODE, Key.NONE, Key.NONE}, /* 4,5 */ {Key.NONE, Key.NONE, Key.NONE}, /* 4,6 */ - {Key.NONE, Key.NONE, Key.NONE} /* 4,7 */ + {Key.NUM0, Key.NONE, Key.LETTER_X} /* 4,7 */ }, { /* ROW 5 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 5,0 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 5,1 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 5,2 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 5,3 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 5,4 */ + {Key.NUM7, Key.NONE, Key.NONE}, /* 5,0 */ + {Key.NUM8, Key.NONE, Key.NONE}, /* 5,1 */ + {Key.NUM9, Key.NONE, Key.NONE}, /* 5,2 */ + {Key.DELETE, Key.NONE, Key.NONE}, /* 5,3 */ + {Key.RESET, Key.NONE, Key.NONE}, /* 5,4 */ {Key.NONE, Key.NONE, Key.NONE}, /* 5,5 */ {Key.NONE, Key.NONE, Key.NONE}, /* 5,6 */ {Key.NONE, Key.NONE, Key.NONE} /* 5,7 */ }, { /* ROW 6 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 6,0 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 6,1 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 6,2 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 6,3 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 6,4 */ + {Key.NUM4, Key.NONE, Key.NONE}, /* 6,0 */ + {Key.NUM5, Key.NONE, Key.NONE}, /* 6,1 */ + {Key.NUM6, Key.NONE, Key.NONE}, /* 6,2 */ + {Key.MULTIPLY, Key.NONE, Key.NONE}, /* 6,3 */ + {Key.DIVIDE, Key.NONE, Key.NONE}, /* 6,4 */ {Key.NONE, Key.NONE, Key.NONE}, /* 6,5 */ {Key.NONE, Key.NONE, Key.NONE}, /* 6,6 */ {Key.NONE, Key.NONE, Key.NONE} /* 6,7 */ }, { /* ROW 7 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 7,0 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 7,1 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 7,2 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 7,3 */ - {Key.NONE, Key.NONE, Key.NONE}, /* 7,4 */ + {Key.NUM1, Key.NONE, Key.NONE}, /* 7,0 */ + {Key.NUM2, Key.NONE, Key.NONE}, /* 7,1 */ + {Key.NUM3, Key.NONE, Key.NONE}, /* 7,2 */ + {Key.PLUS, Key.PLUS_MINUS, Key.NONE}, /* 7,3 */ + {Key.MINUS, Key.NONE, Key.NONE}, /* 7,4 */ {Key.NONE, Key.NONE, Key.NONE}, /* 7,5 */ {Key.NONE, Key.NONE, Key.NONE}, /* 7,6 */ {Key.NONE, Key.NONE, Key.NONE} /* 7,7 */ @@ -586,7 +586,7 @@ public class Keyboard { refresh = true; } else { switch (k) { - case POWER: + case POWEROFF: DisplayManager.INSTANCE.engine.destroy(); break; case NONE: @@ -678,10 +678,6 @@ public class Keyboard { additionalListener = l; } - public static enum Key { - POWER, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK, HISTORY_FORWARD, SURD_MODE, DRG_CYCLE, LETTER_X, LETTER_Y, STEP, SIMPLIFY, BRIGHTNESS_CYCLE, BRIGHTNESS_CYCLE_REVERSE, DOT, NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, PARENTHESIS_OPEN, PARENTHESIS_CLOSE, PLUS, MINUS, PLUS_MINUS, MULTIPLY, DIVIDE, EQUAL, DELETE, RESET, LEFT, RIGHT, UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5, SQRT, ROOT, POWER_OF_2, POWER_OF_x, SINE, COSINE, TANGENT, ARCSINE, ARCCOSINE, ARCTANGENT, PI - } - public static boolean popRefreshRequest() { if (refreshRequest) { refreshRequest = false; @@ -695,49 +691,79 @@ public class Keyboard { /* --coord- - NORMAL - SHIFT - ALPHA -------- - -|0,0---|0,1---|------|0,3---|------|------|0,6---| -|SHIFT |ALPHA |------| ^ |------|------|+BRIGH| -|SHIFT |ALPHA |------| |------|------|-BRIGH| -|SHIFT |ALPHA |------| |------|------| | -|1,0---|1,1---|1,2---|1,3---|1,4---|1,5---|1,6---| -| = | | < | OK | > | Back | Fwd | -| | | | | | | | -| | | | | | | | -|2,0---|2,1---|------|2,3---|------|2,5---|2,6---| -| | SQRT |------| v |------| | | -| | ROOT |------| |------| | | -| | |------| |------| | | -|3,0---|3,1---|3,2---|3,3---|3,4---|3,5---|3,6---| -| | | POW 2| POW x| | | | -| | | | | | | | -| | | | | | | | -|4,0---|4,1---|4,2---|4,3---|4,4---|4,5---|4,6---| -| | | | | |S<=>D | | -| | | | | | | | -| | | | | | | | -|5,0---|5,1---|5,2---|5,3---|5,4---|5,5---|5,6---| -| 7 | 8 | 9 | DEL | RESET | -| | | | | | -| | | | | | -|6,0---|6,1---|6,2---|6,3---|6,4-----------------| -| 4 | 5 | 6 | * | / | -| | | | | | -| | | | | | -|7,0---|7,1---|7,2---|7,3---|7,4-----------------| -| 1 | 2 | 3 | + | - | -| | | | | | -| | | | | | -|4,7---|3,7---|2,7---|1,7---|0,7-----------------| -| 0 | . | | | SIMPLIFY | -| | | |PI | STEP | -| X | Y | Z |DRGCYCL|SOLVE FOR [x] | -|------|------|------|------|--------------------| +Keyboard: + Example button: + |ROW,COLUMN----| + | NORMAL STATE | + | SHIFT STATE | + | ALPHA STATE | + |--------------| + + Physical keyboard: + |0,0-----|0,1-----|########|0,3-----|########|0,5-----|0,6-----| + | SHIFT | ALPHA |########| ^ |########|SETTINGS|+BRIGHT | + | NORMAL | ALPHA |########| |########| |-BRIGHT | + | SHIFT | NORMAL |########| |########| | | + |1,0-----|1,1-----|1,2-----|1,3-----|1,4-----|1,5-----|1,6-----| + | F_4 | | < | OK | > | Back | Fwd | + | F_4 | | | | | | | + | F_4 | | | | | | | + |2,0-----|2,1-----|--------|2,3-----|--------|2,5-----|2,6-----| + | F_3 | SQRT |########| v | BACK | | | + | F_3 | ROOT |########| | | | | + | F_3 | |########| | | | | + |3,0-----|3,1-----|3,2-----|3,3-----|3,4-----|3,5-----|3,6-----| + | F_2 | | POW x | POW 2 | | | | + | F_2 | | | | | | | + | F_2 | | | | | | | + |4,0-----|4,1-----|4,2-----|4,3-----|4,4-----|4,5-----|4,6-----| + | F_1 | | ( | ) | | S<=>D | | + | F_1 | | | | | | | + | F_1 | | | | | | | + |5,0-----|5,1-----|5,2-----|5,3-----|5,4-----|5,5-----|5,6-----| + | 7 | 8 | 9 | DEL | RESET | + | | | | | | + | | | | | | + |6,0-----|6,1-----|6,2-----|6,3-----|6,4-----------------------| + | 4 | 5 | 6 | * | / | + | | | | | | + | | | | | | + |7,0-----|7,1-----|7,2-----|7,3-----|7,4-----------------------| + | 1 | 2 | 3 | + | - | + | | | | | | + | | | | | | + |4,7-----|3,7-----|2,7-----|1,7-----|0,7-----------------------| + | 0 | . | | | SIMPLIFY | + | | | |PI | STEP | + | X | Y | Z |DRG CYCL| | + |--------|--------|--------|--------|--------------------------| +SCREEN F_n: + MathInputScreen: + Default: + [F_1] Normal: Solve for X Shift: Solve for _ Alpha: + [F_2] Normal: Shift: Alpha: + [F_3] Normal: Variables & constants Shift: Alpha: + [F_4] Normal: Functions f(x) Shift: Alpha: + Variable popup: + [F_1] Normal(if constant):Set value Shift: Alpha: + [F_2] Normal: Shift: Alpha: + [F_3] Normal: Shift: Alpha: + [F_4] Normal: Shift: Alpha: + MarioScreen + [F_1] Normal: Shift: Alpha: + [F_2] Normal: Shift: Alpha: + [F_3] Normal: Shift: Alpha: + [F_4] Normal: Shift: Alpha: + ChooseVariableValueScreen + [F_1] Normal: Shift: Alpha: + [F_2] Normal: Shift: Alpha: + [F_3] Normal: Shift: Alpha: + [F_4] Normal: Shift: Alpha: + SolveForXScreen + [F_1] Normal: Shift: Alpha: + [F_2] Normal: Shift: Alpha: + [F_3] Normal: Shift: Alpha: + [F_4] Normal: Shift: Alpha: */ \ No newline at end of file diff --git a/src/main/java/org/warp/picalculator/device/KeyboardEventListener.java b/src/main/java/org/warp/picalculator/device/KeyboardEventListener.java index 60f0c88d..50e317fe 100644 --- a/src/main/java/org/warp/picalculator/device/KeyboardEventListener.java +++ b/src/main/java/org/warp/picalculator/device/KeyboardEventListener.java @@ -1,7 +1,5 @@ package org.warp.picalculator.device; -import org.warp.picalculator.device.Keyboard.Key; - public interface KeyboardEventListener { public abstract boolean keyPressed(Key k); diff --git a/src/main/java/org/warp/picalculator/gui/expression/blocks/BlockVariable.java b/src/main/java/org/warp/picalculator/gui/expression/blocks/BlockVariable.java index e3591ea2..5d5ec01c 100644 --- a/src/main/java/org/warp/picalculator/gui/expression/blocks/BlockVariable.java +++ b/src/main/java/org/warp/picalculator/gui/expression/blocks/BlockVariable.java @@ -1,7 +1,7 @@ package org.warp.picalculator.gui.expression.blocks; import org.warp.picalculator.Error; -import org.warp.picalculator.device.Keyboard.Key; +import org.warp.picalculator.device.Key; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.expression.Caret; import org.warp.picalculator.gui.expression.ExtraMenu; diff --git a/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPUFont.java b/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPUFont.java index f87fbb0b..971c8f3c 100755 --- a/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPUFont.java +++ b/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPUFont.java @@ -25,7 +25,7 @@ public class CPUFont implements BinaryFont { public int charH; public int charS; public int charIntCount; - public LinkedList intervals; + public int[] intervals; public int intervalsTotalSize = 0; public static final int intBits = 31; private final boolean isResource; @@ -167,7 +167,7 @@ public class CPUFont implements BinaryFont { } private void findIntervals() { - intervals = new LinkedList(); + final LinkedList intervals = new LinkedList(); int beginIndex = -1; int endIndex = 0; int intervalSize = 0; @@ -183,7 +183,7 @@ public class CPUFont implements BinaryFont { i = endIndex; if (endIndex >= 0) { intervalSize = endIndex - beginIndex + 1; - intervals.add(new Integer[] {beginIndex, endIndex, intervalSize}); + intervals.add(new int[] {beginIndex, endIndex, intervalSize}); intervalsTotalSize += intervalSize; } beginIndex = -1; @@ -191,7 +191,7 @@ public class CPUFont implements BinaryFont { } int lastIndex = 0; boolean[][] newrawchars = new boolean[intervalsTotalSize][]; - for (Integer[] interval: intervals) { + for (int[] interval: intervals) { if (rawchars.length - (interval[0]) - interval[2] < 0) { System.err.println(interval[0] + "-" + interval[1] + "(" + interval[2] + ")"); System.err.println(rawchars.length - (interval[0]) - interval[2]); @@ -205,6 +205,14 @@ public class CPUFont implements BinaryFont { lastIndex += interval[2]; } rawchars = newrawchars; + final int intervalsSize = intervals.size(); + this.intervals = new int[intervalsSize * 3]; + for (int i = 0; i < intervalsSize; i++) { + int[] interval = intervals.get(i); + this.intervals[i * 3 + 0] = interval[0]; + this.intervals[i * 3 + 1] = interval[1]; + this.intervals[i * 3 + 2] = interval[2]; + } } @SuppressWarnings("unused") @@ -237,14 +245,14 @@ public class CPUFont implements BinaryFont { private int compressIndex(int originalIndex) { int compressedIndex = 0; - for (Integer[] interval : intervals) { - if (interval[0] > originalIndex) { + for (int i = 0; i < intervals.length; i+=3) { + if (intervals[i] > originalIndex) { break; - } else if (originalIndex <= interval[1]) { - compressedIndex+=(originalIndex-interval[0]); + } else if (originalIndex <= intervals[i+1]) { + compressedIndex+=(originalIndex-intervals[i]); break; } else { - compressedIndex+=interval[2]; + compressedIndex+=intervals[i+2]; } } return compressedIndex; @@ -253,12 +261,12 @@ public class CPUFont implements BinaryFont { private int decompressIndex(int compressedIndex) { int originalIndex = 0; int i = 0; - for (Integer[] interval : intervals) { - i+=interval[2]; + for (int intvl = 0; intvl < intervals.length; intvl+=3) { + i+=intervals[intvl+2]; if (i == compressedIndex) { - return interval[1]; + return intervals[intvl+1]; } else if (i > compressedIndex) { - return interval[1] - (i - compressedIndex); + return intervals[intvl+1] - (i - compressedIndex); } } return originalIndex; diff --git a/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/GPUFont.java b/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/GPUFont.java index cf1f2e12..55aaa5ce 100755 --- a/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/GPUFont.java +++ b/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/GPUFont.java @@ -28,7 +28,7 @@ public class GPUFont implements BinaryFont { public int charH; public int minCharIndex; public int maxCharIndex; - public LinkedList intervals; + public int[] intervals; public int intervalsTotalSize = 0; public int memoryWidth; public int memoryHeight; @@ -89,14 +89,14 @@ public class GPUFont implements BinaryFont { private int compressIndex(int originalIndex) { int compressedIndex = 0; - for (Integer[] interval : intervals) { - if (interval[0] > originalIndex) { + for (int i = 0; i < intervals.length; i+=3) { + if (intervals[i] > originalIndex) { break; - } else if (originalIndex <= interval[1]) { - compressedIndex+=(originalIndex-interval[0]); + } else if (originalIndex <= intervals[i+1]) { + compressedIndex+=(originalIndex-intervals[i]); break; } else { - compressedIndex+=interval[2]; + compressedIndex+=intervals[i+2]; } } return compressedIndex; @@ -105,10 +105,10 @@ public class GPUFont implements BinaryFont { private int decompressIndex(int compressedIndex) { int originalIndex = 0; int i = 0; - for (Integer[] interval : intervals) { - i+=interval[2]; + for (int intvl = 0; i < intervals.length; i+=3) { + i+=intervals[intvl+2]; if (i >= compressedIndex) { - return interval[1] - (i - compressedIndex); + return intervals[intvl+1] - (i - compressedIndex); } } return originalIndex; diff --git a/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java b/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java index 79647e18..1bdf4e4d 100755 --- a/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java +++ b/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java @@ -27,12 +27,15 @@ public class GPURenderer implements Renderer { public static GL2ES1 gl; + private static final int ELEMENTS_MAX_COUNT_PER_BUFFER = StaticVars.enableVBO ? 128 : 1; private static final int ELEMENT_VERTICES_COUNT = 6, vertSize = 3, texSize = 2, colSize = 4, - vertBuffer = 0, texBuffer = 1, colBuffer = 2; - private static final int ELEMENTS_MAX_COUNT_PER_BUFFER = StaticVars.enableVBO ? 128 : 1; + vertBuffer = 0, texBuffer = 1, colBuffer = 2, + vertMax = vertSize * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER, + texMax = texSize * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER, + colMax = colSize * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER; - private IntBuffer handlers; + private int[] handlers; private final DeallocationHelper deallocationHelper = new DeallocationHelper(); FloatBuffer fbVertices; FloatBuffer fbTextures; @@ -299,11 +302,11 @@ public class GPURenderer implements Renderer { public void initDrawCycle() { final boolean textureChange = precTexEnabled != currentTexEnabled || precTex != currentTex; if (fbVertices == null) { - fbVertices = Buffers.newDirectFloatBuffer(vertSize * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER); - fbTextures = Buffers.newDirectFloatBuffer(texSize * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER); - fbColors = Buffers.newDirectFloatBuffer(colSize * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER); - handlers = Buffers.newDirectIntBuffer(3); - gl.glGenBuffers(3, handlers); + fbVertices = Buffers.newDirectFloatBuffer(vertMax); + fbTextures = Buffers.newDirectFloatBuffer(texMax); + fbColors = Buffers.newDirectFloatBuffer(colMax); + handlers = new int[3]; + gl.glGenBuffers(3, handlers, 0); } startDrawSegment(false); if (textureChange) { @@ -374,7 +377,7 @@ public class GPURenderer implements Renderer { fbColors.flip(); // gl.glVertexPointer(vertSize, GL.GL_FLOAT, 0, fbVertices); - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, handlers.get(vertBuffer)); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, handlers[vertBuffer]); if (firstBufferTexDataCall) { gl.glBufferData( GL.GL_ARRAY_BUFFER, fbVertices.limit() * Buffers.SIZEOF_FLOAT, @@ -387,7 +390,7 @@ public class GPURenderer implements Renderer { } gl.glVertexPointer(vertSize, GL.GL_FLOAT, 0, 0l); // gl.glTexCoordPointer(texSize, GL.GL_FLOAT, 0, fbTextures); - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, handlers.get(texBuffer)); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, handlers[texBuffer]); if (firstBufferTexDataCall) { gl.glBufferData( GL.GL_ARRAY_BUFFER, fbTextures.limit() * Buffers.SIZEOF_FLOAT, @@ -400,7 +403,7 @@ public class GPURenderer implements Renderer { } gl.glTexCoordPointer(texSize, GL.GL_FLOAT, 0, 0l); // gl.glColorPointer(colSize, GL.GL_FLOAT, 0, fbColors); - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, handlers.get(colBuffer)); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, handlers[colBuffer]); if (firstBufferTexDataCall) { gl.glBufferData( GL.GL_ARRAY_BUFFER, fbColors.limit() * Buffers.SIZEOF_FLOAT, @@ -412,11 +415,10 @@ public class GPURenderer implements Renderer { fbColors); } gl.glColorPointer(colSize, GL.GL_FLOAT, 0, 0l); - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); - fbVertices.limit(fbVertices.capacity()); - fbTextures.limit(fbTextures.capacity()); - fbColors.limit(fbColors.capacity()); + fbVertices.limit(vertMax); + fbTextures.limit(texMax); + fbColors.limit(colMax); gl.glDrawArrays(GL.GL_TRIANGLES, 0, fbElements * ELEMENT_VERTICES_COUNT); //gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, fbElements * ELEMENT_VERTICES_COUNT); firstBufferDataCall = false; diff --git a/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/NEWTWindow.java b/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/NEWTWindow.java index 9d809ccf..d08bbcaa 100755 --- a/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/NEWTWindow.java +++ b/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/NEWTWindow.java @@ -29,8 +29,8 @@ package org.warp.picalculator.gui.graphicengine.gpu; import org.warp.picalculator.StaticVars; +import org.warp.picalculator.device.Key; import org.warp.picalculator.device.Keyboard; -import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; import com.jogamp.newt.event.KeyEvent; @@ -142,7 +142,7 @@ class NEWTWindow implements GLEventListener { public void keyReleased(KeyEvent arg0) { switch (arg0.getKeyCode()) { case KeyEvent.VK_ESCAPE: - Keyboard.keyReleased(Key.POWER); + Keyboard.keyReleased(Key.POWEROFF); break; case KeyEvent.VK_D: Keyboard.keyReleased(Key.debug_DEG); diff --git a/src/main/java/org/warp/picalculator/gui/graphicengine/headless24bit/Headless24bitEngine.java b/src/main/java/org/warp/picalculator/gui/graphicengine/headless24bit/Headless24bitEngine.java index 52f362eb..716c9562 100644 --- a/src/main/java/org/warp/picalculator/gui/graphicengine/headless24bit/Headless24bitEngine.java +++ b/src/main/java/org/warp/picalculator/gui/graphicengine/headless24bit/Headless24bitEngine.java @@ -7,8 +7,8 @@ import org.fusesource.jansi.AnsiConsole; import org.fusesource.jansi.internal.WindowsSupport; import org.warp.picalculator.StaticVars; import org.warp.picalculator.Utils; +import org.warp.picalculator.device.Key; import org.warp.picalculator.device.Keyboard; -import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.gui.graphicengine.RenderingLoop; diff --git a/src/main/java/org/warp/picalculator/gui/graphicengine/headless256/Headless256Engine.java b/src/main/java/org/warp/picalculator/gui/graphicengine/headless256/Headless256Engine.java index fa739c44..1746ea4e 100755 --- a/src/main/java/org/warp/picalculator/gui/graphicengine/headless256/Headless256Engine.java +++ b/src/main/java/org/warp/picalculator/gui/graphicengine/headless256/Headless256Engine.java @@ -7,8 +7,8 @@ import org.fusesource.jansi.AnsiConsole; import org.fusesource.jansi.internal.WindowsSupport; import org.warp.picalculator.StaticVars; import org.warp.picalculator.Utils; +import org.warp.picalculator.device.Key; import org.warp.picalculator.device.Keyboard; -import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.gui.graphicengine.RenderingLoop; import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer; diff --git a/src/main/java/org/warp/picalculator/gui/graphicengine/headless8/Headless8Engine.java b/src/main/java/org/warp/picalculator/gui/graphicengine/headless8/Headless8Engine.java index ee0d0e21..71123712 100644 --- a/src/main/java/org/warp/picalculator/gui/graphicengine/headless8/Headless8Engine.java +++ b/src/main/java/org/warp/picalculator/gui/graphicengine/headless8/Headless8Engine.java @@ -7,8 +7,8 @@ import org.fusesource.jansi.AnsiConsole; import org.fusesource.jansi.internal.WindowsSupport; import org.warp.picalculator.StaticVars; import org.warp.picalculator.Utils; +import org.warp.picalculator.device.Key; import org.warp.picalculator.device.Keyboard; -import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.gui.graphicengine.RenderingLoop; import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer; diff --git a/src/main/java/org/warp/picalculator/gui/screens/ChooseVariableValueScreen.java b/src/main/java/org/warp/picalculator/gui/screens/ChooseVariableValueScreen.java index 570b0ebd..57cd7e84 100755 --- a/src/main/java/org/warp/picalculator/gui/screens/ChooseVariableValueScreen.java +++ b/src/main/java/org/warp/picalculator/gui/screens/ChooseVariableValueScreen.java @@ -2,7 +2,7 @@ package org.warp.picalculator.gui.screens; import org.warp.picalculator.StaticVars; import org.warp.picalculator.Utils; -import org.warp.picalculator.device.Keyboard.Key; +import org.warp.picalculator.device.Key; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Variable.VariableValue; diff --git a/src/main/java/org/warp/picalculator/gui/screens/EmptyScreen.java b/src/main/java/org/warp/picalculator/gui/screens/EmptyScreen.java index 3545866b..0f3144ae 100755 --- a/src/main/java/org/warp/picalculator/gui/screens/EmptyScreen.java +++ b/src/main/java/org/warp/picalculator/gui/screens/EmptyScreen.java @@ -1,6 +1,6 @@ package org.warp.picalculator.gui.screens; -import org.warp.picalculator.device.Keyboard.Key; +import org.warp.picalculator.device.Key; public class EmptyScreen extends Screen { diff --git a/src/main/java/org/warp/picalculator/gui/screens/KeyboardDebugScreen.java b/src/main/java/org/warp/picalculator/gui/screens/KeyboardDebugScreen.java index 7b27c6b3..482411ee 100755 --- a/src/main/java/org/warp/picalculator/gui/screens/KeyboardDebugScreen.java +++ b/src/main/java/org/warp/picalculator/gui/screens/KeyboardDebugScreen.java @@ -1,7 +1,7 @@ package org.warp.picalculator.gui.screens; import org.warp.picalculator.StaticVars; -import org.warp.picalculator.device.Keyboard.Key; +import org.warp.picalculator.device.Key; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.graphicengine.Renderer; diff --git a/src/main/java/org/warp/picalculator/gui/screens/LoadingScreen.java b/src/main/java/org/warp/picalculator/gui/screens/LoadingScreen.java index efbe19d4..df553dfd 100755 --- a/src/main/java/org/warp/picalculator/gui/screens/LoadingScreen.java +++ b/src/main/java/org/warp/picalculator/gui/screens/LoadingScreen.java @@ -1,7 +1,7 @@ package org.warp.picalculator.gui.screens; import org.warp.picalculator.StaticVars; -import org.warp.picalculator.device.Keyboard.Key; +import org.warp.picalculator.device.Key; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.GraphicUtils; diff --git a/src/main/java/org/warp/picalculator/gui/screens/MarioScreen.java b/src/main/java/org/warp/picalculator/gui/screens/MarioScreen.java index b960e071..2a7d4eb2 100755 --- a/src/main/java/org/warp/picalculator/gui/screens/MarioScreen.java +++ b/src/main/java/org/warp/picalculator/gui/screens/MarioScreen.java @@ -3,8 +3,8 @@ package org.warp.picalculator.gui.screens; import java.io.IOException; import org.warp.picalculator.StaticVars; +import org.warp.picalculator.device.Key; import org.warp.picalculator.device.Keyboard; -import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.Skin; diff --git a/src/main/java/org/warp/picalculator/gui/screens/MathInputScreen.java b/src/main/java/org/warp/picalculator/gui/screens/MathInputScreen.java index f7f86586..db25723d 100755 --- a/src/main/java/org/warp/picalculator/gui/screens/MathInputScreen.java +++ b/src/main/java/org/warp/picalculator/gui/screens/MathInputScreen.java @@ -7,8 +7,8 @@ import org.warp.picalculator.Error; import org.warp.picalculator.Errors; import org.warp.picalculator.StaticVars; import org.warp.picalculator.Utils; +import org.warp.picalculator.device.Key; import org.warp.picalculator.device.Keyboard; -import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.expression.InputContext; import org.warp.picalculator.gui.expression.blocks.Block; diff --git a/src/main/java/org/warp/picalculator/gui/screens/SolveEquationScreen.java b/src/main/java/org/warp/picalculator/gui/screens/SolveForXScreen.java similarity index 90% rename from src/main/java/org/warp/picalculator/gui/screens/SolveEquationScreen.java rename to src/main/java/org/warp/picalculator/gui/screens/SolveForXScreen.java index e4f1b181..dcaa0dec 100755 --- a/src/main/java/org/warp/picalculator/gui/screens/SolveEquationScreen.java +++ b/src/main/java/org/warp/picalculator/gui/screens/SolveForXScreen.java @@ -1,15 +1,15 @@ package org.warp.picalculator.gui.screens; import org.warp.picalculator.StaticVars; -import org.warp.picalculator.device.Keyboard.Key; +import org.warp.picalculator.device.Key; import org.warp.picalculator.gui.DisplayManager; -public class SolveEquationScreen extends Screen { +public class SolveForXScreen extends Screen { @SuppressWarnings("unused") private final MathInputScreen es; - public SolveEquationScreen(MathInputScreen es) { + public SolveForXScreen(MathInputScreen es) { super(); canBeInHistory = false;