added windows specific timer class

This commit is contained in:
georgemoralis 2023-06-29 13:20:34 +03:00
parent 20c0960cc6
commit f5dd2e83a9
1 changed files with 76 additions and 5 deletions

View File

@ -1,42 +1,113 @@
#include "Timer.h"
#ifdef _WIN64
#include "windows.h"
#endif
Lib::Timer::Timer()
{
#ifdef _WIN64
LARGE_INTEGER f;
QueryPerformanceFrequency(&f);
m_Frequency = f.QuadPart;
#endif
}
void Lib::Timer::Start()
{
#ifdef _WIN64
LARGE_INTEGER c;
QueryPerformanceCounter(&c);
m_StartTime = c.QuadPart;
m_is_timer_paused = false;
#endif
}
void Lib::Timer::Pause()
{
#ifdef _WIN64
LARGE_INTEGER c;
QueryPerformanceCounter(&c);
m_PauseTime = c.QuadPart;
#endif
m_is_timer_paused = true;
}
void Lib::Timer::Resume()
{
u64 current_time = 0;
#ifdef _WIN64
LARGE_INTEGER c;
QueryPerformanceCounter(&c);
current_time = c.QuadPart;
#endif
m_StartTime += current_time - m_PauseTime;
m_is_timer_paused = false;
}
bool Lib::Timer::IsPaused() const
{
return false;
return m_is_timer_paused;
}
double Lib::Timer::GetTimeMsec() const
{
return 0.0;
if (m_is_timer_paused)
{
return 1000.0 * (static_cast<double>(m_PauseTime - m_StartTime)) / static_cast<double>(m_Frequency);
}
u64 current_time = 0;
#ifdef _WIN64
LARGE_INTEGER c;
QueryPerformanceCounter(&c);
current_time = c.QuadPart;
#endif
return 1000.0 * (static_cast<double>(current_time - m_StartTime)) / static_cast<double>(m_Frequency);
}
double Lib::Timer::GetTimeSec() const
{
return 0.0;
if (m_is_timer_paused)
{
return (static_cast<double>(m_PauseTime - m_StartTime)) / static_cast<double>(m_Frequency);
}
u64 current_time = 0;
#ifdef _WIN64
LARGE_INTEGER c;
QueryPerformanceCounter(&c);
current_time = c.QuadPart;
#endif
return (static_cast<double>(current_time - m_StartTime)) / static_cast<double>(m_Frequency);
}
u64 Lib::Timer::GetTicks() const
{
return u64();
if (m_is_timer_paused)
{
return (m_PauseTime - m_StartTime);
}
u64 current_time = 0;
#ifdef _WIN64
LARGE_INTEGER c;
QueryPerformanceCounter(&c);
current_time = c.QuadPart;
#endif
return (current_time - m_StartTime);
}
u64 Lib::Timer::GetFrequency() const
{
return u64();
return m_Frequency;
}