Source

LiquidMastachEngine / Backup / 18.01.04 / Libaries / Timer.cpp

Full commit
/*
* LIQUID MASTAH Engine
* (c) GOSU code '2003
* http://www.algorithms.prv.pl
*
* Autor: Piotr Wach aka Wachu  
* e-mail: gosuwachu@o2.pl
*/

#include "Timer.h"


bool CTimer::InitializeTimer()
{
	if (!QueryPerformanceFrequency(&m_ticksPerSecond))
	{
		// system nie posiada licznika czasu o dużej dokładnoœci
		return false;
	}
	else
	{
		QueryPerformanceCounter(&m_startTime);
		return true;
	}
} 


float CTimer::GetElapsedSeconds(unsigned long elapsedFrames)
{
	static LARGE_INTEGER s_lastTime = m_startTime;
	LARGE_INTEGER currentTime;

	QueryPerformanceCounter(&currentTime);

	float seconds =  ((float)currentTime.QuadPart - (float)s_lastTime.QuadPart) / (float)m_ticksPerSecond.QuadPart;

	// "zeruje" licznik czasu
	s_lastTime = currentTime;

	return seconds;
} 


float CTimer::GetFPS(unsigned long elapsedFrames)
{
	static LARGE_INTEGER s_lastTime = m_startTime;
	LARGE_INTEGER currentTime;

	QueryPerformanceCounter(&currentTime);

	float fps = (float)elapsedFrames * (float)m_ticksPerSecond.QuadPart / ((float)currentTime.QuadPart - (float)s_lastTime.QuadPart);

	// "zeruje" licznik czasu
	s_lastTime = currentTime;

	return fps;
}