Optimize wait/message (#9086)
* add `IExecutor.yield` to optimize `wait` * add MessageType.label. and add outSuccess * remove `MessageType.label` in support `marks` * amend * amend
This commit is contained in:
@@ -49,6 +49,7 @@ public class LExecutor{
|
|||||||
public Var[] vars = {};
|
public Var[] vars = {};
|
||||||
public Var counter;
|
public Var counter;
|
||||||
public int[] binds;
|
public int[] binds;
|
||||||
|
public boolean yield;
|
||||||
|
|
||||||
public int iptIndex = -1;
|
public int iptIndex = -1;
|
||||||
public LongSeq graphicsBuffer = new LongSeq();
|
public LongSeq graphicsBuffer = new LongSeq();
|
||||||
@@ -1128,6 +1129,7 @@ public class LExecutor{
|
|||||||
}else{
|
}else{
|
||||||
//skip back to self.
|
//skip back to self.
|
||||||
exec.var(varCounter).numval --;
|
exec.var(varCounter).numval --;
|
||||||
|
exec.yield = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(state.updateId != frameId){
|
if(state.updateId != frameId){
|
||||||
@@ -1143,6 +1145,7 @@ public class LExecutor{
|
|||||||
public void run(LExecutor exec){
|
public void run(LExecutor exec){
|
||||||
//skip back to self.
|
//skip back to self.
|
||||||
exec.var(varCounter).numval --;
|
exec.var(varCounter).numval --;
|
||||||
|
exec.yield = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1539,11 +1542,12 @@ public class LExecutor{
|
|||||||
|
|
||||||
public static class FlushMessageI implements LInstruction{
|
public static class FlushMessageI implements LInstruction{
|
||||||
public MessageType type = MessageType.announce;
|
public MessageType type = MessageType.announce;
|
||||||
public int duration;
|
public int duration, outSuccess;
|
||||||
|
|
||||||
public FlushMessageI(MessageType type, int duration){
|
public FlushMessageI(MessageType type, int duration, int outSuccess){
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
|
this.outSuccess = outSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FlushMessageI(){
|
public FlushMessageI(){
|
||||||
@@ -1551,16 +1555,20 @@ public class LExecutor{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(LExecutor exec){
|
public void run(LExecutor exec){
|
||||||
if(headless && type != MessageType.mission) return;
|
//set default to succes
|
||||||
|
exec.setnum(outSuccess, 1);
|
||||||
|
if(headless && type != MessageType.mission) {
|
||||||
|
exec.textBuffer.setLength(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//skip back to self until possible
|
|
||||||
//TODO this is guaranteed desync on servers - I don't see a good solution
|
|
||||||
if(
|
if(
|
||||||
type == MessageType.announce && ui.hasAnnouncement() ||
|
type == MessageType.announce && ui.hasAnnouncement() ||
|
||||||
type == MessageType.notify && ui.hudfrag.hasToast() ||
|
type == MessageType.notify && ui.hudfrag.hasToast() ||
|
||||||
type == MessageType.toast && ui.hasAnnouncement()
|
type == MessageType.toast && ui.hasAnnouncement()
|
||||||
){
|
){
|
||||||
exec.var(varCounter).numval --;
|
//set outSuccess=false to let user retry.
|
||||||
|
exec.setnum(outSuccess, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1425,7 +1425,7 @@ public class LStatements{
|
|||||||
@RegisterStatement("message")
|
@RegisterStatement("message")
|
||||||
public static class FlushMessageStatement extends LStatement{
|
public static class FlushMessageStatement extends LStatement{
|
||||||
public MessageType type = MessageType.announce;
|
public MessageType type = MessageType.announce;
|
||||||
public String duration = "3";
|
public String duration = "3", outSuccess = "success";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(Table table){
|
public void build(Table table){
|
||||||
@@ -1444,12 +1444,14 @@ public class LStatements{
|
|||||||
}, Styles.logict, () -> {}).size(160f, 40f).padLeft(2).color(table.color);
|
}, Styles.logict, () -> {}).size(160f, 40f).padLeft(2).color(table.color);
|
||||||
|
|
||||||
switch(type){
|
switch(type){
|
||||||
case announce, toast -> {
|
case announce, toast -> {
|
||||||
table.add(" for ");
|
table.add(" for ");
|
||||||
fields(table, duration, str -> duration = str);
|
fields(table, duration, str -> duration = str);
|
||||||
table.add(" secs ");
|
table.add(" secs ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
table.add(" success ");
|
||||||
|
fields(table, outSuccess, str -> outSuccess = str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1459,7 +1461,7 @@ public class LStatements{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LInstruction build(LAssembler builder){
|
public LInstruction build(LAssembler builder){
|
||||||
return new FlushMessageI(type, builder.var(duration));
|
return new FlushMessageI(type, builder.var(duration), builder.var(outSuccess));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -514,6 +514,10 @@ public class LogicBlock extends Block{
|
|||||||
for(int i = 0; i < (int)accumulator; i++){
|
for(int i = 0; i < (int)accumulator; i++){
|
||||||
executor.runOnce();
|
executor.runOnce();
|
||||||
accumulator --;
|
accumulator --;
|
||||||
|
if(executor.yield){
|
||||||
|
executor.yield = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user