Example #1
0
        private void Run()
        {
            BeforeRun?.Invoke(this, new EventArgs());
            int lastTick    = Environment.TickCount;
            int firstTick   = lastTick;
            int currentTick = 0;

            working = true;

            while (working)
            {
                currentTick = Environment.TickCount;
                cntrLogic.Tick();
                TickEventArgs args = new TickEventArgs(new Time(TimeSpan.FromMilliseconds(Environment.TickCount - firstTick), TimeSpan.FromMilliseconds(currentTick - lastTick)), cntrLogic);
                LogicTick?.Invoke(this, args);
                DrawTick?.Invoke(this, args);

                if (args.Stop)
                {
                    break;
                }

                lastTick = Environment.TickCount;

                if (this.LimitFrames)
                {
                    long passed = lastTick - currentTick + 1;
                    if (passed <= timePerTick)
                    {
                        Thread.Sleep((int)(timePerTick - passed));
                    }
                }
            }
            AfterRun?.Invoke(this, new EventArgs());
        }
Example #2
0
 /// <summary>
 /// Gets the set of delegates set to execute when LogicTick fires.
 /// </summary>
 public static Delegate[] LogicInvokers()
 {
     return(LogicTick != null?LogicTick.GetInvocationList() : new Delegate[0]);
 }