fixed cpu engine

This commit is contained in:
Andrea Cavalli 2018-04-02 00:47:33 +02:00
parent b9ee67b3af
commit 095c6a0094
10 changed files with 80 additions and 19 deletions

1
.gitignore vendored
View File

@ -14,6 +14,7 @@ font_gputest12.rft
font_gputest2.rft
font_gputest3.png
font_gputest4.png
font_gputest4.xcf
manager2/
VBO_Example.java

View File

@ -89,6 +89,11 @@
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>

View File

@ -1,10 +1,12 @@
package org.warp.picalculator;
import org.warp.picalculator.device.PIHardwareDisplay;
import org.warp.picalculator.gui.CalculatorHUD;
import org.warp.picalculator.gui.screens.KeyboardDebugScreen;
public class KeyboardTest {
public static void main(String[] args) throws InterruptedException, Error {
new Main(new KeyboardDebugScreen(), args);
new Main(new KeyboardDebugScreen(), new PIHardwareDisplay(), new CalculatorHUD(), args);
}
}

View File

@ -11,6 +11,8 @@ import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.PIHardwareDisplay;
import org.warp.picalculator.gui.CalculatorHUD;
import org.warp.picalculator.gui.DisplayManager;
import org.warp.picalculator.gui.HUD;
import org.warp.picalculator.gui.HardwareDisplay;
import org.warp.picalculator.gui.screens.LoadingScreen;
import org.warp.picalculator.gui.screens.Screen;
import org.warp.picalculator.math.rules.RulesManager;
@ -22,10 +24,10 @@ public class Main {
public static Main instance;
public static String[] args;
public Main(String[] args) throws InterruptedException, Error {
this(new LoadingScreen(), args);
this(new LoadingScreen(), new PIHardwareDisplay(), new CalculatorHUD(), args);
}
public Main(Screen screen, String[] args) throws InterruptedException, Error {
public Main(Screen screen, HardwareDisplay disp, HUD hud, String[] args) throws InterruptedException, Error {
System.out.println("WarpPI Calculator");
instance = this;
Main.args = args;
@ -33,7 +35,7 @@ public class Main {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
Thread.currentThread().setName("Main thread");
beforeStart();
new DisplayManager(new PIHardwareDisplay(), new CalculatorHUD(), screen, "WarpPI Calculator by Andrea Cavalli (@Cavallium)");
new DisplayManager(disp, hud, screen, "WarpPI Calculator by Andrea Cavalli (@Cavallium)");
afterStart();
if (screen instanceof LoadingScreen) {
((LoadingScreen) screen).loaded = true;

View File

@ -11,4 +11,8 @@ public interface Skin {
public boolean isInitialized();
public void use(GraphicEngine d);
public int getSkinWidth();
public int getSkinHeight();
}

View File

@ -307,4 +307,14 @@ public class CPUFont implements BinaryFont {
return true;
}
@Override
public int getSkinWidth() {
return -1;
}
@Override
public int getSkinHeight() {
return -1;
}
}

View File

@ -54,9 +54,11 @@ public class CPURenderer implements Renderer {
}
}
private void glDrawSkin(int x0, int y0, int s0, int t0, int s1, int t1, boolean transparent) {
private void glDrawSkin(int x0, int y0, int x1, int y1, int s0, int t0, int s1, int t1, boolean transparent) {
x0 += StaticVars.screenPos[0];
y0 += StaticVars.screenPos[1];
double incrementX = Math.abs((double)(x1-x0)/(double)(s1-s0));
double incrementY = Math.abs((double)(y1-y0)/(double)(t1-t0));
int oldColor;
int newColor;
final int onex = s0 <= s1 ? 1 : -1;
@ -102,25 +104,30 @@ public class CPURenderer implements Renderer {
}
y0 = 0;
}
int pixelX;
int pixelY;
for (int texx = 0; texx < s1 - s0; texx++) {
for (int texy = 0; texy < t1 - t0; texy++) {
pixelX = (x0 + texx * onex + width);
pixelY = (y0 + texy * oney + height);
if (pixelX - (pixelX % size[0]) == 0) {
final int index = pixelX + pixelY * size[0];
if (canvas2d.length > index) {
newColor = currentSkin.skinData[(s0 + texx) + (t0 + texy) * currentSkin.skinSize[0]];
for (double pixelX = 0; pixelX < x1-x0; pixelX++) {
for (double pixelY = 0; pixelY < y1-y0; pixelY++) {
final int index = (int) (x0+pixelX + (y0+pixelY) * size[0]);
if (canvas2d.length > index) {
int texx = (int) (pixelX / incrementX);
int texy = (int) (pixelY / incrementY);
int skinIndex = (int) (s0 + texx + (t0 + texy) * currentSkin.skinSize[0]);
if (skinIndex >= 0 && skinIndex < currentSkin.skinData.length) {
newColor = currentSkin.skinData[skinIndex];
final int a = (int) ((double)(newColor >> 24 & 0xFF) * ((double)(color >> 24 & 0xFF)/(double)0xFF));
int r = (int) ((double)(newColor >> 16 & 0xFF) * ((double)(color >> 16 & 0xFF)/(double)0xFF));
int g = (int) ((double)(newColor >> 8 & 0xFF) * ((double)(color >> 8 & 0xFF)/(double)0xFF));
int b = (int) ((double)(newColor & 0xFF) * ((double)(color & 0xFF)/(double)0xFF));
newColor = a << 24 | r << 16 | g << 8 | b;
if (transparent) {
oldColor = canvas2d[index];
final float a2 = (newColor >> 24 & 0xFF) / 255f;
final float a1 = 1f - a2;
final int r = (int) ((oldColor >> 16 & 0xFF) * a1 + (newColor >> 16 & 0xFF) * a2);
final int g = (int) ((oldColor >> 8 & 0xFF) * a1 + (newColor >> 8 & 0xFF) * a2);
final int b = (int) ((oldColor & 0xFF) * a1 + (newColor & 0xFF) * a2);
r = (int) ((oldColor >> 16 & 0xFF) * a1 + (newColor >> 16 & 0xFF) * a2);
g = (int) ((oldColor >> 8 & 0xFF) * a1 + (newColor >> 8 & 0xFF) * a2);
b = (int) ((oldColor & 0xFF) * a1 + (newColor & 0xFF) * a2);
newColor = 0xFF000000 | r << 16 | g << 8 | b;
}
canvas2d[index] = newColor;
}
}
@ -169,7 +176,7 @@ public class CPURenderer implements Renderer {
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth,
float uvHeight) {
if (currentSkin != null) {
glDrawSkin((int) x, (int) y, (int) uvX, (int) uvY, (int) (uvWidth + uvX), (int) (uvHeight + uvY), true);
glDrawSkin((int) x, (int) y, (int) (x + width), (int) (y + height), (int) uvX, (int) uvY, (int) (uvWidth + uvX), (int) (uvHeight + uvY), true);
} else {
glFillColor(x, y, width, height);
}

View File

@ -58,4 +58,14 @@ public class CPUSkin implements Skin {
return true;
}
@Override
public int getSkinWidth() {
return skinSize[0];
}
@Override
public int getSkinHeight() {
return skinSize[1];
}
}

View File

@ -234,4 +234,14 @@ public class GPUFont implements BinaryFont {
public boolean isInitialized() {
return initialized;
}
@Override
public int getSkinWidth() {
return this.memoryWidth;
}
@Override
public int getSkinHeight() {
return this.memoryHeight;
}
}

View File

@ -67,4 +67,14 @@ public class GPUSkin implements Skin {
return initialized;
}
@Override
public int getSkinWidth() {
return w;
}
@Override
public int getSkinHeight() {
return h;
}
}