/// <summary>
            /// This should be called ONCE in main(). Advances the internal state and runs all jobs that would happen on that tick.
            /// </summary>
            /// <param name="args">the <c>string</c> that <c>Main(string args, UpdateType)</c> gets handed</param>
            /// <param name="updateType">the <c>UpdateType</c> that <c>Main(string args, UpdateType)</c> gets handed</param>
            /// <param name="execute">if false, only the state will be advanced, commands parsed, but no jobs will be excuted</param>
            /// <see cref="RuntimeEnvironment"/>
            public void Tick(string args, UpdateType updateType, bool execute = true)
            {
                if ((updateType & KnownCommandUpdateTypes) != 0)
                {
                    execute &= ParseArgs(args); commanded = 2;
                }

                if ((Online && execute) || EvaluationMode)
                {
                    if (!EvaluationMode && CurrentTick % interval == 0)
                    {
                        foreach (var job in Jobs)
                        {
                            if (job.Value.active && CurrentTick % job.Value.RequeueInterval == 0)
                            {
                                TryQueueJob(job.Key);
                            }
                        }
                    }

                    ProcessRunningJobs();

                    bool hasstates = false;
                    foreach (var name in JobNames)
                    {
                        if (EvaluationMode || (!Jobs[name].lazy && RunningJobs[name] != null))
                        {
                            hasstates = true;
                            ++FastTick;
                            if (FastTick > FastTickMax)
                            {
                                ++FastTickMax;
                            }
                            if ((ThisProgram.Runtime.UpdateFrequency & UpdateFrequency.Update1) == 0)
                            {
                                ThisProgram.Runtime.UpdateFrequency |= UpdateFrequency.Once;
                            }
                            break;
                        }
                    }

                    if (!hasstates)
                    {
                        FastTick = 0;
                        SyncTick();
                        UpdateOnline();
                    }
                }

                CurrentTick += FastTick > 0 ? 1 : CurrentTickrate;
                ++SymbolTick;
                LastRuntime = ThisProgram.Runtime.LastRunTimeMs;
                if (commanded == 0)
                {
                    _AverageRuntime.AddValue(LastRuntime);
                }
                TimeSinceLastCall = ThisProgram.Runtime.TimeSinceLastRun.TotalSeconds * 1000 + LastRuntime;
                ContinousTime    += TimeSinceLastCall;

                if (EvaluationMode)
                {
                    if (EvaluatingState < 0 && RunningJobs.Values.All(x => x == null))
                    {
                        TryQueueJob(EvaluateJobList[0]);
                        EvaluatingState = 0;
                        EvaluationDone  = false;
                    }
                    else if (EvaluatingState > -1)
                    {
                        if (EvaluationDone)
                        {
                            AverageJobRuntimes[EvaluateJobList[0]].Update();
                            EvaluateJobList.RemoveAt(0);
                            EvaluationMode  = EvaluateJobList.Any();
                            EvaluatingState = -1;
                            StatsStrings[3].Invalidate();
                            UpdateOnline();
                        }
                        else
                        {
                            AverageJobRuntimes[EvaluateJobList[0]].AddParse(EvaluatingState, LastRuntime);
                            ++EvaluatingState;
                            EvaluationDone = RunningJobs[EvaluateJobList[0]] == null;
                        }
                    }
                }

                if (!firstrun && LastRuntime > MaxRunTime)
                {
                    if (commanded == 0)
                    {
                        MaxRunTime = LastRuntime;
                    }

                    if (commanded != 0 && (LastRuntime > MaxTolerableRuntime || LastRuntime > MaxRunTime * 3))
                    {
                        SaveEvent(string.Format("Command{0} took {1:0.}ms", execute && RunningJobs.Values.Any(x => x != null)?"+Jobs:(" + LastRunJobs + ")":"", MaxRunTime));
                    }
                    else if (LastRuntime > MaxTolerableRuntime || LastRuntime > MaxRunTime * 1.3)
                    {
                        SaveEvent(string.Format("Jobs: ({0}) took {1:0.}ms", LastRunJobs, MaxRunTime));
                    }
                }
                else if (CurrentTick > 10)
                {
                    firstrun = false;
                }

                if (EchoState)
                {
                    Echo(StatsString(-1));
                }
                if (DisplayState && CurrentTick % 10 == 0)
                {
                    PBscreen.WriteText(StatsStrings[-2].Value, false);
                    PBkeyboard.WriteText(TickString() + "\n" + TickString() + "\n" + TickString(), false);
                }

                SystemInfoList.Invalidate();
                JobInfoList.Invalidate();
                for (int i = -3; i < 4; ++i)
                {
                    StatsStrings[i].Invalidate();
                }

                commanded -= commanded > 0 ? 1 : 0;
            }
Exemplo n.º 2
0
 public void Invalidate()
 {
     transformedShapeCached.Invalidate();
     undoOverlapDone = false;
 }