/*
 * $Id: framerate.h 4270 2016-11-06 11:02:47Z antonin.misek-skoda-auto.cz $
 *
 * Description  : One line description of file.
 * Author       : Vaclav Kyba <mail/Jabber: vaseo1@gmail.com>  <ICQ: 98576293>
 * 
 * Purpose      :
 *     Long description of what the file is for.
 */


#ifndef __FRAMERATE__H__
#define __FRAMERATE__H__

#include <wx/stopwatch.h>


namespace VRUT
{
	///Frame rate counting class
	class FrameRate
	{
	protected:
		///Total frames counted
		unsigned long totalFrames;
		///\c totalFrames value from last notification
		unsigned long lastFrames;
		///Frames per second
		float fps;
		///Stop watch for precise timing
		wxStopWatch stopWatch;

	public:
		///Class constructor
		FrameRate()
		{
			totalFrames = lastFrames = 0;
			fps = 0;
		}

		///Update and get frames per second
		float GetFPS() const
		{
			return fps;
		}

		unsigned long GetTotalFrames() const
		{
			return totalFrames;
		}

		///Increment frame counter and update framerate
		void IncFrame()
		{
			totalFrames++;
			long currTime = stopWatch.Time();
			if (currTime > 500)
			{
				fps = 1000.0f * double(totalFrames - lastFrames) / double(currTime);
				if (totalFrames > 0x0fffffff)
					totalFrames = 0;
				lastFrames = totalFrames;
				stopWatch.Start();
			}
		}
	};
}

#endif
