private void Validate(SqProgram program, SqRequirements capabilities, List <string> messages) { //bool hasTimer = (capabilities & SqRequirements.Timer) == SqRequirements.Timer; bool hasCM = (capabilities & SqRequirements.ControlModule) == SqRequirements.ControlModule; var repeatPos = program.Commands.FindIndex(x => x.Cmd == "repeat"); if (repeatPos != -1 && repeatPos != program.Commands.Count - 1) { Log.WriteFormat(Parser.LOG_CAT, LogLevel.Warning, "Unreachable code found in @{0}: all commands after /repeat will never executed", program.Name); } if (repeatPos != -1 && !program.Commands.Take(repeatPos).Any(x => Commands.CmdDefs[x.Cmd].IsWait)) { Log.WriteFormat(Parser.LOG_CAT, LogLevel.Warning, "Where is no any wait command before /repeat in @{0}. Script will wait 1 tock to prevent \"Script Too Complex\" exception", program.Name); } /* * SqCommand cmd = null; * if (!hasTimer && (cmd = program.Commands.FirstOrDefault(x => (Commands.CmdDefs[x.Cmd].Requirements & SqRequirements.Timer) != 0)) != null) * { * Log.WriteFormat(Parser.LOG_CAT, LogLevel.Warning, "@{0} contains /{1} command, but where is no timer to execute it", program.Name, cmd.Cmd); * }*/ SqCommand cmd = null; if (!hasCM && (cmd = program.Commands.FirstOrDefault(x => (Commands.CmdDefs[x.Cmd].Requirements & SqRequirements.ControlModule) != 0)) != null) { Log.WriteFormat(Parser.LOG_CAT, LogLevel.Warning, "@{0} contains /{1} command, but Control Module mod is not loaded", program.Name, cmd.Cmd); } // if (!hasCM && program.Commands) }
IEnumerable <bool> ExecuteProgram(SqProgram program) { if (program.TimeToWait > TimerController.IgnoreDelayLessThen) { yield break; } Log.WriteFormat(LOG_CAT, LogLevel.Verbose, "executing \"{0}\"", program.Name); program._cycle++; // Breaking OOP a bit while (program.currentCommand < program.Commands.Count) { var cmd = program.Commands[program.currentCommand]; if (cmd._cycle == program._cycle) { Log.WriteFormat(LOG_CAT, LogLevel.Warning, "Program \"{0}\" is not sleeping. Forcing break.", program.Name); goto pause; } else { cmd._cycle = program._cycle; } /*var result =*/ cmd.Run(program); program.currentCommand++; if (program.TimeToWait > TimerController.IgnoreDelayLessThen) { goto pause; // achievement unlocked: use goto } yield return(false); } // "else" for condition of while loop scheduledPrograms.Remove(program.Name); pause: yield return(true); }
private void ExecuteLine(string arg) { var parse = new ParserTask(arg); parse.Done = r => { SqProgram prog = r.Item1?.FirstOrDefault(); if (r.Item1 != null) { string tempName = "_run_" + runtime.GenerateProgramId().ToString(); prog.Commands.Add(Commands.CmdDefs["unload"].Materialize(new object[] { tempName })); // todo: prog.Name = tempName; runtime.RegisterPrograms(new SqProgram[] { prog }); runtime.StartProgram(tempName); } }; sch.EnqueueTask(parse); }