mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 03:33:48 +00:00
Changes profiler to use the high precision timer built into windows.
Also removes the legacy GetTickCount() fallback as that is no longer necessary in modern versions of windows (Windows XP and greater support QueryPerformanceCounter)
This commit is contained in:
parent
3b111b14cc
commit
dee89e25b8
3 changed files with 38 additions and 110 deletions
|
|
@ -30,14 +30,11 @@
|
|||
class Win32Timer : public PlatformTimer
|
||||
{
|
||||
private:
|
||||
U32 mTickCountCurrent;
|
||||
U32 mTickCountNext;
|
||||
S64 mPerfCountCurrent;
|
||||
S64 mPerfCountNext;
|
||||
S64 mFrequency;
|
||||
F64 mPerfCountRemainderCurrent;
|
||||
F64 mPerfCountRemainderNext;
|
||||
bool mUsingPerfCounter;
|
||||
public:
|
||||
|
||||
Win32Timer()
|
||||
|
|
@ -45,43 +42,26 @@ public:
|
|||
mPerfCountRemainderCurrent = 0.0f;
|
||||
mPerfCountRemainderNext = 0.0f;
|
||||
|
||||
// Attempt to use QPC for high res timing, otherwise fallback to GTC.
|
||||
mUsingPerfCounter = QueryPerformanceFrequency((LARGE_INTEGER *) &mFrequency);
|
||||
if(mUsingPerfCounter)
|
||||
mUsingPerfCounter = QueryPerformanceCounter((LARGE_INTEGER *) &mPerfCountCurrent);
|
||||
QueryPerformanceFrequency((LARGE_INTEGER *) &mFrequency);
|
||||
QueryPerformanceCounter((LARGE_INTEGER *) &mPerfCountCurrent);
|
||||
mPerfCountNext = 0.0;
|
||||
if (!mUsingPerfCounter)
|
||||
mTickCountCurrent = GetTickCount();
|
||||
else
|
||||
mTickCountCurrent = 0;
|
||||
mTickCountNext = 0;
|
||||
}
|
||||
|
||||
const S32 getElapsedMs()
|
||||
{
|
||||
if(mUsingPerfCounter)
|
||||
{
|
||||
// Use QPC, update remainders so we don't leak time, and return the elapsed time.
|
||||
QueryPerformanceCounter( (LARGE_INTEGER *) &mPerfCountNext);
|
||||
F64 elapsedF64 = (1000.0 * F64(mPerfCountNext - mPerfCountCurrent) / F64(mFrequency));
|
||||
elapsedF64 += mPerfCountRemainderCurrent;
|
||||
U32 elapsed = (U32)mFloor(elapsedF64);
|
||||
mPerfCountRemainderNext = elapsedF64 - F64(elapsed);
|
||||
// Use QPC, update remainders so we don't leak time, and return the elapsed time.
|
||||
QueryPerformanceCounter( (LARGE_INTEGER *) &mPerfCountNext);
|
||||
F64 elapsedF64 = (1000.0 * F64(mPerfCountNext - mPerfCountCurrent) / F64(mFrequency));
|
||||
elapsedF64 += mPerfCountRemainderCurrent;
|
||||
U32 elapsed = (U32)mFloor(elapsedF64);
|
||||
mPerfCountRemainderNext = elapsedF64 - F64(elapsed);
|
||||
|
||||
return elapsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do something naive with GTC.
|
||||
mTickCountNext = GetTickCount();
|
||||
return mTickCountNext - mTickCountCurrent;
|
||||
}
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
// Do some simple copying to reset the timer to 0.
|
||||
mTickCountCurrent = mTickCountNext;
|
||||
mPerfCountCurrent = mPerfCountNext;
|
||||
mPerfCountRemainderCurrent = mPerfCountRemainderNext;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue