Exemplo n.º 1
0
        /// <summary>
        ///     Advances the animation by one frame.
        /// </summary>
        private void AdvanceFrame()
        {
            //  Invoke the OnFrameEnd action
            OnFrameEnd?.Invoke();

            //  Increment the frame index
            CurrentFrameIndex += _direction;

            //  Handle the animation direcion type
            switch (CurrentAnimation.Direction)
            {
            case AnimationLoopDirection.Forward:
                ForwardAnimationLoopCheck();
                break;

            case AnimationLoopDirection.Reverse:
                ReverseAnimationLoopCheck();
                break;

            case AnimationLoopDirection.PingPong:
                PingPongAnimationLoopCheck();
                break;

            default:
                throw new Exception($"Unknown AnimationLoopDirection value given");
            }

            //  Set the CurrentFrame
            CurrentFrame = Frames[CurrentFrameIndex];

            //  Set the duration
            FrameTimer = (double)CurrentFrame.Duration;
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Updates this
        /// </summary>
        /// <param name="deltaTime">
        ///     The amount of time, in seconds, that have passed since
        ///     the last update.  Usually gathered from GameTime.ElapsedTime.TotalSeconds
        /// </param>
        public override void Update(float deltaTime)
        {
            if (Animating)
            {
                //  Using an epsilon of 0.0001 to check for equality between
                //  the Framtimer (double) and duration (float).  This is to handle
                //  edge cases where precision loss in the float may cause this to
                //  skip.
                if (Math.Abs(FrameTimer - CurrentFrame.duration) < 0.0001)
                {
                    //  We're at the beginning of the frame so invoke the
                    //  Action
                    OnFrameBegin?.Invoke();
                }

                //  Decrement the frame timer
                FrameTimer -= deltaTime;

                //  Check if we need to move on to the next frame
                if (FrameTimer <= 0)
                {
                    //  We're now at the end of a frame, so invoke the action
                    OnFrameEnd?.Invoke();

                    //  Increment the frame index
                    CurrentFrameIndex += 1;

                    //  Check that we are still within the bounds of the animations frames
                    if (CurrentFrameIndex > CurrentAnimation.to)
                    {
                        //  Loop back to the beginning of the animations frame
                        CurrentFrameIndex = CurrentAnimation.from;

                        //  Since we looped, invoke the loop aciton
                        OnAnimationLoop?.Invoke();
                    }

                    //  Set the CurrentFrame
                    CurrentFrame = _animationDefinition.Frames[CurrentFrameIndex];

                    //  Set the Duration
                    FrameTimer = (double)CurrentFrame.duration;
                }
            }
        }
Exemplo n.º 3
0
 protected virtual void OnFrameStartEnd(TickEventArgs tickEventArgs)
 => OnFrameEnd?.Invoke(this, tickEventArgs);
Exemplo n.º 4
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...
        }