// Jason Brillante "Damdoshi"
// Hanged Bunny Studio 2014
//
// HBS Game

#ifndef				__HBS_CHRONO_HPP__
# define			__HBS_CHRONO_HPP__
# include			<SFML/Graphics.hpp>

namespace			hbs
{
  class				Chrono
  {
  protected:
    sf::Clock			clock;
    sf::Time			time_per_frame;
    sf::Time			time_since_last;

  public:
    void			Reset(void)
    {
      clock.restart();
    }
    unsigned int		Time(void)
    {
      sf::Time			elapsed = clock.restart();
      int			cnt;

      time_since_last += elapsed;
      cnt = time_since_last.asMicroseconds() / time_per_frame.asMicroseconds();
      time_since_last =
	sf::microseconds(time_since_last.asMicroseconds() - cnt * time_per_frame.asMicroseconds());
      return (cnt);
    }
    int64_t			Timestamp(void)
    {
      sf::Time			elapsed = clock.getElapsedTime();

      return (elapsed.asMicroseconds());
    }
    unsigned int		GetDelay(void)
    {
      return (time_per_frame.asMicroseconds());
    }

    Chrono(double		frequency)
    {
      time_per_frame = sf::microseconds(1000000.0 / frequency);
      time_since_last = sf::Time::Zero;
    }
    Chrono(void)
    {}
    ~Chrono(void) {}
  };
}

#endif	//			__HBS_CHRONO_HPP__
