Triangle draw command

This commit is contained in:
Anuken
2020-08-11 12:54:39 -04:00
parent 188171ec03
commit 25e04ca3e5
4 changed files with 26 additions and 12 deletions

View File

@@ -406,9 +406,9 @@ public class LExecutor{
public static class DrawI implements LInstruction{ public static class DrawI implements LInstruction{
public byte type; public byte type;
public int target; public int target;
public int x, y, p1, p2, p3; public int x, y, p1, p2, p3, p4;
public DrawI(byte type, int target, int x, int y, int p1, int p2, int p3){ public DrawI(byte type, int target, int x, int y, int p1, int p2, int p3, int p4){
this.type = type; this.type = type;
this.target = target; this.target = target;
this.x = x; this.x = x;
@@ -416,6 +416,7 @@ public class LExecutor{
this.p1 = p1; this.p1 = p1;
this.p2 = p2; this.p2 = p2;
this.p3 = p3; this.p3 = p3;
this.p4 = p4;
} }
public DrawI(){ public DrawI(){
@@ -428,7 +429,7 @@ public class LExecutor{
//add graphics calls, cap graphics buffer size //add graphics calls, cap graphics buffer size
if(exec.graphicsBuffer.size < maxGraphicsBuffer){ if(exec.graphicsBuffer.size < maxGraphicsBuffer){
exec.graphicsBuffer.add(DisplayCmd.get(type, exec.numi(x), exec.numi(y), exec.numi(p1), exec.numi(p2), exec.numi(p3))); exec.graphicsBuffer.add(DisplayCmd.get(type, exec.numi(x), exec.numi(y), exec.numi(p1), exec.numi(p2), exec.numi(p3), exec.numi(p4)));
} }
} }
} }

View File

@@ -123,8 +123,8 @@ public class LStatements{
@RegisterStatement("draw") @RegisterStatement("draw")
public static class DrawStatement extends LStatement{ public static class DrawStatement extends LStatement{
public GraphicsType type = GraphicsType.line; public GraphicsType type = GraphicsType.clear;
public String x = "0", y = "0", p1 = "0", p2 = "0", p3 = "0"; public String x = "0", y = "0", p1 = "0", p2 = "0", p3 = "0", p4 = "0";
@Override @Override
public void build(Table table){ public void build(Table table){
@@ -188,6 +188,16 @@ public class LStatements{
s.row(); s.row();
fields(s, "rotation", p3, v -> p3 = v); fields(s, "rotation", p3, v -> p3 = v);
break; break;
case triangle:
fields(s, "x", x, v -> x = v);
fields(s, "y", y, v -> y = v);
s.row();
fields(s, "x2", p1, v -> p1 = v);
fields(s, "y2", p2, v -> p2 = v);
s.row();
fields(s, "x3", p3, v -> p3 = v);
fields(s, "y3", p4, v -> p4 = v);
break;
} }
}).expand().left(); }).expand().left();
@@ -200,7 +210,7 @@ public class LStatements{
@Override @Override
public LInstruction build(LAssembler builder){ public LInstruction build(LAssembler builder){
return new DrawI((byte)type.ordinal(), 0, builder.var(x), builder.var(y), builder.var(p1), builder.var(p2), builder.var(p3)); return new DrawI((byte)type.ordinal(), 0, builder.var(x), builder.var(y), builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4));
} }
} }

View File

@@ -19,7 +19,8 @@ public class LogicDisplay extends Block{
commandRect = 4, commandRect = 4,
commandLineRect = 5, commandLineRect = 5,
commandPoly = 6, commandPoly = 6,
commandLinePoly = 7; commandLinePoly = 7,
commandTriangle = 8;
public int maxSides = 25; public int maxSides = 25;
@@ -60,7 +61,7 @@ public class LogicDisplay extends Block{
long c = commands.removeFirst(); long c = commands.removeFirst();
byte type = DisplayCmd.type(c); byte type = DisplayCmd.type(c);
int x = DisplayCmd.x(c), y = DisplayCmd.y(c), int x = DisplayCmd.x(c), y = DisplayCmd.y(c),
p1 = DisplayCmd.p1(c), p2 = DisplayCmd.p2(c), p3 = DisplayCmd.p3(c); p1 = DisplayCmd.p1(c), p2 = DisplayCmd.p2(c), p3 = DisplayCmd.p3(c), p4 = DisplayCmd.p4(c);
switch(type){ switch(type){
case commandClear: Core.graphics.clear(x/255f, y/255f, p1/255f, 1f); break; case commandClear: Core.graphics.clear(x/255f, y/255f, p1/255f, 1f); break;
@@ -69,6 +70,7 @@ public class LogicDisplay extends Block{
case commandLineRect: Lines.rect(x, y, p1, p2); break; case commandLineRect: Lines.rect(x, y, p1, p2); break;
case commandPoly: Fill.poly(x, y, Math.min(p1, maxSides), p2, p3); break; case commandPoly: Fill.poly(x, y, Math.min(p1, maxSides), p2, p3); break;
case commandLinePoly: Lines.poly(x, y, Math.min(p1, maxSides), p2, p3); break; case commandLinePoly: Lines.poly(x, y, Math.min(p1, maxSides), p2, p3); break;
case commandTriangle: Fill.tri(x, y, p1, p2, p3, p4); break;
case commandColor: this.color = Color.toFloatBits(x, y, p1, 255); Draw.color(this.color); break; case commandColor: this.color = Color.toFloatBits(x, y, p1, 255); Draw.color(this.color); break;
case commandStroke: this.stroke = x; Lines.stroke(x); break; case commandStroke: this.stroke = x; Lines.stroke(x); break;
} }
@@ -94,7 +96,8 @@ public class LogicDisplay extends Block{
rect, rect,
lineRect, lineRect,
poly, poly,
linePoly; linePoly,
triangle;
public static final GraphicsType[] all = values(); public static final GraphicsType[] all = values();
} }
@@ -105,7 +108,7 @@ public class LogicDisplay extends Block{
//each coordinate is only 8 bits, limiting size to 256x256 //each coordinate is only 8 bits, limiting size to 256x256
//anything larger than that would be excessive anyway //anything larger than that would be excessive anyway
@StructField(9) @StructField(8)
public int x, y, p1, p2, p3; public int x, y, p1, p2, p3, p4;
} }
} }

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=618135d9b6f36fbe0838e0a5128ac1283457be82 archash=f30313ec8a5abf51ff0314a65babf5d95047fda3