Hacky wait time save/loading for processors
This commit is contained in:
@@ -20,6 +20,7 @@ import mindustry.graphics.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.io.TypeIO.*;
|
||||
import mindustry.logic.*;
|
||||
import mindustry.logic.LExecutor.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.ConstructBlock.*;
|
||||
@@ -36,6 +37,8 @@ public class LogicBlock extends Block{
|
||||
public static final int maxNameLength = 32;
|
||||
|
||||
private static final IntSet usedBuildings = new IntSet();
|
||||
private static final IntSeq waitIndices = new IntSeq();
|
||||
private static final FloatSeq waitValues = new FloatSeq();
|
||||
|
||||
public int maxInstructionScale = 5;
|
||||
public int instructionsPerTick = 1;
|
||||
@@ -700,7 +703,7 @@ public class LogicBlock extends Block{
|
||||
|
||||
@Override
|
||||
public byte version(){
|
||||
return 3;
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -746,6 +749,21 @@ public class LogicBlock extends Block{
|
||||
|
||||
TypeIO.writeString(write, tag);
|
||||
write.s(iconTag);
|
||||
|
||||
waitIndices.clear();
|
||||
waitValues.clear();
|
||||
for(int i = 0; i < executor.instructions.length; i ++){
|
||||
if(executor.instructions[i] instanceof WaitI wait){
|
||||
waitValues.add(wait.curTime);
|
||||
waitIndices.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
write.s(waitIndices.size);
|
||||
for(int i = 0; i < waitIndices.size; i++){
|
||||
write.s(waitIndices.get(i));
|
||||
write.f(waitValues.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -784,6 +802,29 @@ public class LogicBlock extends Block{
|
||||
//skip memory, it isn't used anymore
|
||||
read.skip(memory * 8);
|
||||
|
||||
if(privileged && revision >= 2){
|
||||
ipt = Mathf.clamp(read.s(), 1, maxInstructionsPerTick);
|
||||
}
|
||||
|
||||
if(revision >= 3){
|
||||
tag = TypeIO.readString(read);
|
||||
iconTag = (char)read.us();
|
||||
}
|
||||
|
||||
IntSeq waitIndices = new IntSeq();
|
||||
FloatSeq waitValues = new FloatSeq();
|
||||
|
||||
//read wait times into list for processing once the asm is loaded
|
||||
if(revision >= 4){
|
||||
int waits = read.us();
|
||||
for(int i = 0; i < waits; i++){
|
||||
int index = read.us();
|
||||
float value = read.f();
|
||||
waitIndices.add(index);
|
||||
waitValues.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
loadBlock = () -> updateCode(code, false, asm -> {
|
||||
//load up the variables that were stored
|
||||
for(int i = 0; i < varcount; i++){
|
||||
@@ -801,17 +842,16 @@ public class LogicBlock extends Block{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//wait times can only be applied once the instructions are loaded an exist
|
||||
for(int i = 0; i < waitIndices.size; i++){
|
||||
int waitIndex = waitIndices.get(i);
|
||||
if(waitIndex >= 0 && waitIndex < asm.instructions.length && asm.instructions[waitIndex] instanceof WaitI wait){
|
||||
wait.curTime = waitValues.get(i);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(privileged && revision >= 2){
|
||||
ipt = Mathf.clamp(read.s(), 1, maxInstructionsPerTick);
|
||||
}
|
||||
|
||||
if(revision >= 3){
|
||||
tag = TypeIO.readString(read);
|
||||
iconTag = (char)read.us();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user