Clock::Clock()
{
LARGE_INTEGER qwTicksPerSec;
QueryPerformanceFrequency( &qwTicksPerSec );
_TicksPerSecond = qwTicksPerSec.QuadPart;
Start();
}
void Clock::Start()
{
LARGE_INTEGER qwTime;
QueryPerformanceCounter( &qwTime );
_StartTime = qwTime.QuadPart;
}
double Clock::Elapsed()
{
LARGE_INTEGER qwTime;
QueryPerformanceCounter( &qwTime );
return double(qwTime.QuadPart - _StartTime) / double(_TicksPerSecond);
}
ComponentTimer::ComponentTimer(const String &prompt)
{
_prompt = prompt;
Console::WriteLine(String("Begin: ") + prompt);
}
ComponentTimer::~ComponentTimer()
{
Console::WriteLine(String("End: ") + String(_timer.Elapsed()) + String("s"));
}
void FrameTimer::Start(float fFramesPerSec)
{
LARGE_INTEGER qwTicksPerSec;
QueryPerformanceFrequency( &qwTicksPerSec );
TPS = qwTicksPerSec.QuadPart;
Prev_Time = GetTime();
m_FPS = fFramesPerSec;
m_SPF = 1.0f / m_FPS;
Paused = false;
NullFramesLeft = 0; }
void FrameTimer::Pause()
{
Paused = true;
NullFramesLeft = 5;
}
void FrameTimer::Frame()
{
__int64 curTime = GetTime();
if(!Paused) {
m_SPF = float(curTime - Prev_Time) / float(TPS) * 0.2f + 0.8f * m_SPF; m_FPS = 1.0f / m_SPF; } else {
if(NullFramesLeft) NullFramesLeft--; else Paused = false;
}
Prev_Time = curTime; }
void FrameTimer::SetFPS(float NewFPS)
{
__int64 curTime = GetTime();
m_FPS = NewFPS;
m_SPF = 1.0f / m_FPS; Prev_Time = curTime;
}
__int64 FrameTimer::GetTime()
{
LARGE_INTEGER qwTime;
QueryPerformanceCounter( &qwTime ); return qwTime.QuadPart;
}
void FrameTimer::IgnoreTime()
{
Prev_Time = GetTime(); }