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:
WayZer 2023-10-07 01:20:53 +08:00 committed by GitHub
parent 5c0c8dcd43
commit 84dc5550ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 9 deletions

View File

@ -49,6 +49,7 @@ public class LExecutor{
public Var[] vars = {};
public Var counter;
public int[] binds;
public boolean yield;
public int iptIndex = -1;
public LongSeq graphicsBuffer = new LongSeq();
@ -1128,6 +1129,7 @@ public class LExecutor{
}else{
//skip back to self.
exec.var(varCounter).numval --;
exec.yield = true;
}
if(state.updateId != frameId){
@ -1143,6 +1145,7 @@ public class LExecutor{
public void run(LExecutor exec){
//skip back to self.
exec.var(varCounter).numval --;
exec.yield = true;
}
}
@ -1539,11 +1542,12 @@ public class LExecutor{
public static class FlushMessageI implements LInstruction{
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.duration = duration;
this.outSuccess = outSuccess;
}
public FlushMessageI(){
@ -1551,16 +1555,20 @@ public class LExecutor{
@Override
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(
type == MessageType.announce && ui.hasAnnouncement() ||
type == MessageType.notify && ui.hudfrag.hasToast() ||
type == MessageType.toast && ui.hasAnnouncement()
){
exec.var(varCounter).numval --;
//set outSuccess=false to let user retry.
exec.setnum(outSuccess, 0);
return;
}

View File

@ -1425,7 +1425,7 @@ public class LStatements{
@RegisterStatement("message")
public static class FlushMessageStatement extends LStatement{
public MessageType type = MessageType.announce;
public String duration = "3";
public String duration = "3", outSuccess = "success";
@Override
public void build(Table table){
@ -1444,12 +1444,14 @@ public class LStatements{
}, Styles.logict, () -> {}).size(160f, 40f).padLeft(2).color(table.color);
switch(type){
case announce, toast -> {
case announce, toast -> {
table.add(" for ");
fields(table, duration, str -> duration = str);
table.add(" secs ");
}
}
table.add(" success ");
fields(table, outSuccess, str -> outSuccess = str);
}
@Override
@ -1459,7 +1461,7 @@ public class LStatements{
@Override
public LInstruction build(LAssembler builder){
return new FlushMessageI(type, builder.var(duration));
return new FlushMessageI(type, builder.var(duration), builder.var(outSuccess));
}
@Override

View File

@ -514,6 +514,10 @@ public class LogicBlock extends Block{
for(int i = 0; i < (int)accumulator; i++){
executor.runOnce();
accumulator --;
if(executor.yield){
executor.yield = false;
break;
}
}
}
}