Exemplo n.º 1
0
        private void FrameTimerMethod()
        {
            while (!_exitTimerThread)
            {
                while (IsPaused)
                {
                    Thread.Sleep(100);
                }

                int currentFps = FPS;

                if (currentFps == 0)
                {
                    OnFrameStart?.Invoke();

                    continue;
                }

                int sleepTimePerFrame = 1000 / currentFps;

                for (int i = 0; i < currentFps; i++)
                {
                    _stopwatch.Restart();

                    OnFrameStart?.Invoke();

                    _stopwatch.Stop();

                    int currentSleepTime = sleepTimePerFrame - (int)_stopwatch.ElapsedMilliseconds;

                    if (currentSleepTime >= 0)
                    {
                        Thread.Sleep(currentSleepTime);
                    }
                }
            }
        }
Exemplo n.º 2
0
 protected virtual void OnFrameStartEvent(TickEventArgs tickEventArgs)
 => OnFrameStart?.Invoke(this, tickEventArgs);
Exemplo n.º 3
0
        // Main Loop
        private static void Run()
        {
            Initialize();

            double _largestRenderTime = 0D;
            double renderTimeSum      = 0D;
            int    renderCount        = 0;

            new Scheduler(() =>
            {
                averageRenderTime = (float)(renderTimeSum / renderCount);
                largestRenderTime = (float)(_largestRenderTime);

                //Print ($"Performance summary:\n\tAverage Render Time: {averageRenderTime}\n\tLargest Render Time: {largestRenderTime}");

                _largestRenderTime = 0D;
                renderTimeSum      = 0D;
                renderCount        = 0;
            }).Start(1f);

            // Loop while DAE is supposed to be running
            while (IsRunning)
            {
                void CheckShutdown()
                {
                    if (IsShuttingDown)
                    {
                        IsRunning = false;
                    }
                }

                Time.Update();

                CheckWindowInput();

                if (windows.Count == 0)
                {
                    CheckShutdown();
                    continue;
                }

                UpdateMousePosition();

                OnFrameStart?.Invoke();

                Scheduler.allSchedulers.actual.ForEach(sch => sch.Update());

                rootBuffer.Clear(Color.black);

                rootCanvas.OnMouseMove(mousePosition);

                double renderTime = Performance.Analize(() => Render());

                if (renderTime > _largestRenderTime)
                {
                    _largestRenderTime = renderTime;
                }

                renderTimeSum += renderTime;

                renderCount++;

                //Logger.Print ("Rendering took " + ( timer.Elapsed.TotalMilliseconds ) + "ms to complete.");

                Scheduler.allSchedulers.Update();

                OnFrameEnd?.Invoke();

                Present();

                // Check if we're supposed to shutdown DAE and thus, the main loop we're currently in
                CheckShutdown();
            }

            // End of the Run method, the Start method should begin shutting down DAE now...
        }