mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-07 05:50:54 +07:00
WIP logic display transform matrix support
This commit is contained in:
parent
755c369496
commit
e3b24ac980
@ -1025,14 +1025,17 @@ public class LExecutor{
|
||||
exec.textBuffer.setLength(0);
|
||||
}
|
||||
}else{
|
||||
int num1 = exec.numi(p1);
|
||||
int num1 = exec.numi(p1), xval = packSign(exec.numi(x)), yval = packSign(exec.numi(y));
|
||||
|
||||
if(type == LogicDisplay.commandImage){
|
||||
num1 = exec.obj(p1) instanceof UnlockableContent u ? u.iconId : 0;
|
||||
}else if(type == LogicDisplay.commandScale){
|
||||
xval = packSign((int)(exec.numf(x) / LogicDisplay.scaleStep));
|
||||
yval = packSign((int)(exec.numf(y) / LogicDisplay.scaleStep));
|
||||
}
|
||||
|
||||
//add graphics calls, cap graphics buffer size
|
||||
exec.graphicsBuffer.add(DisplayCmd.get(type, packSign(exec.numi(x)), packSign(exec.numi(y)), packSign(num1), packSign(exec.numi(p2)), packSign(exec.numi(p3)), packSign(exec.numi(p4))));
|
||||
exec.graphicsBuffer.add(DisplayCmd.get(type, xval, yval, packSign(num1), packSign(exec.numi(p2)), packSign(exec.numi(p3)), packSign(exec.numi(p4))));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,6 +260,13 @@ public class LStatements{
|
||||
}, 2, cell -> cell.size(165, 50)));
|
||||
}, Styles.logict, () -> {}).size(165, 40).color(s.color).left().padLeft(2);
|
||||
}
|
||||
case translate, scale -> {
|
||||
fields(s, "x", x, v -> x = v);
|
||||
fields(s, "y", y, v -> y = v);
|
||||
}
|
||||
case rotate -> {
|
||||
fields(s, "degrees", p1, v -> p1 = v);
|
||||
}
|
||||
}
|
||||
}).expand().left();
|
||||
}
|
||||
|
@ -4,8 +4,10 @@ import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.graphics.gl.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
@ -29,7 +31,15 @@ public class LogicDisplay extends Block{
|
||||
commandTriangle = 9,
|
||||
commandImage = 10,
|
||||
//note that this command actually only draws 1 character, unpacked in instruction
|
||||
commandPrint = 11;
|
||||
commandPrint = 11,
|
||||
|
||||
commandTranslate = 12,
|
||||
commandScale = 13,
|
||||
commandRotate = 14,
|
||||
commandResetTransform = 15
|
||||
;
|
||||
|
||||
public static final float scaleStep = 0.05f;
|
||||
|
||||
public int maxSides = 25;
|
||||
|
||||
@ -58,6 +68,7 @@ public class LogicDisplay extends Block{
|
||||
public float color = Color.whiteFloatBits;
|
||||
public float stroke = 1f;
|
||||
public LongQueue commands = new LongQueue(256);
|
||||
public @Nullable Mat transform;
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
@ -79,14 +90,18 @@ public class LogicDisplay extends Block{
|
||||
if(!commands.isEmpty()){
|
||||
Draw.draw(Draw.z(), () -> {
|
||||
Tmp.m1.set(Draw.proj());
|
||||
Tmp.m2.set(Draw.trans());
|
||||
Draw.proj(0, 0, displaySize, displaySize);
|
||||
if(transform != null){
|
||||
Draw.trans(transform);
|
||||
}
|
||||
buffer.begin();
|
||||
Draw.color(color);
|
||||
Lines.stroke(stroke);
|
||||
|
||||
while(!commands.isEmpty()){
|
||||
long c = commands.removeFirst();
|
||||
byte type = DisplayCmd.type(c);
|
||||
int type = DisplayCmd.type(c);
|
||||
int x = unpackSign(DisplayCmd.x(c)), y = unpackSign(DisplayCmd.y(c)),
|
||||
p1 = unpackSign(DisplayCmd.p1(c)), p2 = unpackSign(DisplayCmd.p2(c)), p3 = unpackSign(DisplayCmd.p3(c)), p4 = unpackSign(DisplayCmd.p4(c));
|
||||
|
||||
@ -117,11 +132,16 @@ public class LogicDisplay extends Block{
|
||||
Draw.rect(Tmp.tr1, x + Tmp.tr1.width/2f + glyph.xoffset, y + Tmp.tr1.height/2f + glyph.yoffset + Fonts.logic.getData().capHeight + Fonts.logic.getData().ascent, Tmp.tr1.width, Tmp.tr1.height);
|
||||
}
|
||||
}
|
||||
case commandTranslate -> Draw.trans((transform == null ? (transform = new Mat()) : transform).translate(x, y));
|
||||
case commandScale -> Draw.trans((transform == null ? (transform = new Mat()) : transform).scale(x * scaleStep, y * scaleStep));
|
||||
case commandRotate-> Draw.trans((transform == null ? (transform = new Mat()) : transform).rotate(p1));
|
||||
case commandResetTransform -> Draw.trans((transform == null ? (transform = new Mat()) : transform).idt());
|
||||
}
|
||||
}
|
||||
|
||||
buffer.end();
|
||||
Draw.proj(Tmp.m1);
|
||||
Draw.trans(Tmp.m2);
|
||||
Draw.reset();
|
||||
});
|
||||
}
|
||||
@ -135,6 +155,41 @@ public class LogicDisplay extends Block{
|
||||
Draw.blend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte version(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
|
||||
if(transform != null){
|
||||
write.bool(true);
|
||||
for(int i = 0; i < transform.val.length; i++){
|
||||
write.f(transform.val[i]);
|
||||
}
|
||||
}else{
|
||||
write.bool(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
|
||||
if(revision >= 1){
|
||||
boolean hasTransform = read.bool();
|
||||
if(hasTransform){
|
||||
transform = new Mat();
|
||||
|
||||
for(int i = 0; i < transform.val.length; i++){
|
||||
transform.val[i] = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(){
|
||||
super.remove();
|
||||
@ -163,7 +218,12 @@ public class LogicDisplay extends Block{
|
||||
triangle,
|
||||
image,
|
||||
//note that this command actually only draws 1 character, unpacked in instruction
|
||||
print;
|
||||
print,
|
||||
translate,
|
||||
scale,
|
||||
rotate,
|
||||
reset
|
||||
;
|
||||
|
||||
public static final GraphicsType[] all = values();
|
||||
}
|
||||
@ -171,7 +231,7 @@ public class LogicDisplay extends Block{
|
||||
@Struct
|
||||
static class DisplayCmdStruct{
|
||||
@StructField(4)
|
||||
public byte type;
|
||||
public int type;
|
||||
|
||||
//at least 9 bits are required for full 360 degrees
|
||||
@StructField(10)
|
||||
|
Loading…
Reference in New Issue
Block a user