You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

32 lines
836 B

#include "timer.h"
Timer::Timer()
{
mCurrentThread = GetCurrentThread();
DWORD_PTR systemAffinityMask;
GetProcessAffinityMask(GetCurrentProcess(), &mProcessAffinityMask, &systemAffinityMask);
SetThreadAffinityMask(mCurrentThread, 1);
QueryPerformanceFrequency(&mCPUFrequency);
SetThreadAffinityMask(mCurrentThread, mProcessAffinityMask);
}
void Timer::Start()
{
SetThreadAffinityMask(mCurrentThread, 1);
QueryPerformanceCounter(&mStart);
SetThreadAffinityMask(mCurrentThread, mProcessAffinityMask);
}
int Timer::GetPassedTickers()
{
SetThreadAffinityMask(mCurrentThread, 1);
QueryPerformanceCounter(&mEnd);
SetThreadAffinityMask(mCurrentThread, mProcessAffinityMask);
return (int)(mEnd.QuadPart - mStart.QuadPart);
}
float Timer::GetPassedTime()
{
return (float)GetPassedTickers() / (float)mCPUFrequency.QuadPart;
}