Don't reset processors when links change

This commit is contained in:
Anuken
2021-02-04 18:19:56 -05:00
parent c48034e420
commit 54754cd177

View File

@@ -64,7 +64,7 @@ public class LogicBlock extends Block{
entity.links.add(out); entity.links.add(out);
} }
entity.updateCode(); entity.updateCode(entity.code, true, null);
}); });
} }
@@ -277,15 +277,11 @@ public class LogicBlock extends Block{
return bname + outnum; return bname + outnum;
} }
public void updateCode(){
updateCode(code);
}
public void updateCode(String str){ public void updateCode(String str){
updateCodeVars(str, null); updateCode(str, false, null);
} }
public void updateCodeVars(String str, Cons<LAssembler> assemble){ public void updateCode(String str, boolean keep, Cons<LAssembler> assemble){
if(str != null){ if(str != null){
code = str; code = str;
@@ -317,6 +313,19 @@ public class LogicBlock extends Block{
asm.putConst("@links", executor.links.length); asm.putConst("@links", executor.links.length);
asm.putConst("@ipt", instructionsPerTick); asm.putConst("@ipt", instructionsPerTick);
if(keep){
//store any older variables
for(Var var : executor.vars){
boolean unit = var.name.equals("@unit");
if(!var.constant || unit){
BVar dest = asm.getVar(var.name);
if(dest != null && (!dest.constant || unit)){
dest.value = var.isobj ? var.objval : var.numval;
}
}
}
}
//inject any extra variables //inject any extra variables
if(assemble != null){ if(assemble != null){
assemble.get(asm); assemble.get(asm);
@@ -397,7 +406,7 @@ public class LogicBlock extends Block{
} }
if(changed){ if(changed){
updateCode(); updateCode(code, true, null);
} }
if(enabled){ if(enabled){
@@ -555,7 +564,7 @@ public class LogicBlock extends Block{
//skip memory, it isn't used anymore //skip memory, it isn't used anymore
read.skip(memory * 8); read.skip(memory * 8);
updateCodeVars(code, asm -> { updateCode(code, false, asm -> {
//load up the variables that were stored //load up the variables that were stored
for(int i = 0; i < varcount; i++){ for(int i = 0; i < varcount; i++){