This commit is contained in:
2025-05-13 02:46:21 +03:00
parent 143e16692e
commit 86914b7fcc
610 changed files with 92343 additions and 2 deletions
+60
View File
@@ -0,0 +1,60 @@
#include "Timer.h"
#include <Windows.h>
//#define TIMER_TGT
namespace LifeCore
{
Timer::Timer()
:timeElapsed(0)
{
#ifdef TIMER_TGT
if(refCount == 0)
timeBeginPeriod(1);
refCount++;
#else
QueryPerformanceFrequency((LARGE_INTEGER *)&perfFreq);
#endif
}
Timer::~Timer()
{
#ifdef TIMER_TGT
refCount--;
if(refCount == 0)
timeEndPeriod(1);
#endif
}
void Timer::Start()
{
#ifdef TIMER_TGT
lastTime = timeGetTime();
#else
DWORD_PTR old_mask = SetThreadAffinityMask(GetCurrentThread(), 0);
QueryPerformanceCounter((LARGE_INTEGER *)&lastTime);
SetThreadAffinityMask(GetCurrentThread(), old_mask);
#endif
}
void Timer::Stop()
{
#ifdef TIMER_TGT
curTime = timeGetTime();
diff = curTime - lastTime;
timeElapsed = 1.0 / (double)diff; //time in SECONDS
#else
DWORD_PTR old_mask = SetThreadAffinityMask(GetCurrentThread(), 0);
QueryPerformanceCounter((LARGE_INTEGER *)&curTime);
SetThreadAffinityMask(GetCurrentThread(), old_mask);
if(lastTime == 0)
timeElapsed = 0;
else
{
timeElapsed = (float)((double)(curTime - lastTime) / (double)perfFreq);
}
#endif
}
float Timer::getTimeElapsed()
{
return timeElapsed;
}
}