mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-12 02:49:30 +07:00
GetLink instruction
This commit is contained in:
parent
54dcf06722
commit
1de3217738
core/src/mindustry
@ -29,6 +29,7 @@ public class LExecutor{
|
||||
|
||||
public LongSeq graphicsBuffer = new LongSeq();
|
||||
public StringBuilder textBuffer = new StringBuilder();
|
||||
public Building[] links = {};
|
||||
|
||||
public boolean initialized(){
|
||||
return instructions != null && vars != null && instructions.length > 0;
|
||||
@ -161,6 +162,27 @@ public class LExecutor{
|
||||
}
|
||||
}
|
||||
|
||||
public static class GetLinkI implements LInstruction{
|
||||
public int output, index;
|
||||
|
||||
public GetLinkI(int output, int index){
|
||||
this.index = index;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public GetLinkI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
int address = exec.numi(index);
|
||||
|
||||
if(address >= 0 && address < exec.links.length){
|
||||
exec.setobj(output, exec.links[address]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ReadI implements LInstruction{
|
||||
public int target, position, output;
|
||||
|
||||
|
@ -56,6 +56,30 @@ public class LStatements{
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("read")
|
||||
public static class GetLinkStatement extends LStatement{
|
||||
public String output = "result", address = "0";
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
field(table, output, str -> output = str);
|
||||
|
||||
table.add(" = link# ");
|
||||
|
||||
field(table, address, str -> address = str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LCategory category(){
|
||||
return LCategory.io;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LInstruction build(LAssembler builder){
|
||||
return new GetLinkI(builder.var(output), builder.var(address));
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("write")
|
||||
public static class WriteStatement extends LStatement{
|
||||
public String input = "result", target = "cell1", address = "0";
|
||||
@ -120,7 +144,6 @@ public class LStatements{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RegisterStatement("draw")
|
||||
public static class DrawStatement extends LStatement{
|
||||
public GraphicsType type = GraphicsType.clear;
|
||||
|
@ -262,11 +262,22 @@ public class LogicBlock extends Block{
|
||||
|
||||
//store connections
|
||||
for(LogicLink link : links){
|
||||
if(link.active && validLink(world.build(link.x, link.y))){
|
||||
if(link.active && (link.valid = validLink(world.build(link.x, link.y)))){
|
||||
asm.putConst(link.name, world.build(link.x, link.y));
|
||||
}
|
||||
}
|
||||
|
||||
//store link objects
|
||||
executor.links = new Building[links.count(l -> l.valid && l.active)];
|
||||
int index = 0;
|
||||
for(LogicLink link : links){
|
||||
if(link.active && link.valid){
|
||||
executor.links[index ++] = world.build(link.x, link.y);
|
||||
}
|
||||
}
|
||||
|
||||
asm.putConst("@links", executor.links.length);
|
||||
|
||||
//store any older variables
|
||||
for(Var var : executor.vars){
|
||||
if(!var.constant){
|
||||
|
Loading…
Reference in New Issue
Block a user