using System;
using MonoGame.FourEngine;
using MonoGame.FourEngine.Components;

namespace Rotor.Win32.Entities
{
    public class FpsCounter : Entity
    {
        public int Frames { get; private set; }

        private TimeSpan _elapsed;
        private int _frames;

        public FpsCounter()
        {
            Components.Add(new ActionComponent(Count));
        }

        private void Count(UpdateEventArgs args)
        {
            _elapsed += args.DeltaTime;
            if (_elapsed.Seconds >= 1)
            {
                Frames = _frames;
                _elapsed = TimeSpan.Zero;
                _frames = 0;
            }
            _frames++;
        }
    }
}