2023-06-29 12:17:05 +02:00
|
|
|
#include "Timer.h"
|
|
|
|
|
2023-06-29 12:20:34 +02:00
|
|
|
#ifdef _WIN64
|
|
|
|
#include "windows.h"
|
|
|
|
#endif
|
|
|
|
|
2023-06-29 12:17:05 +02:00
|
|
|
Lib::Timer::Timer()
|
|
|
|
{
|
2023-06-29 12:20:34 +02:00
|
|
|
#ifdef _WIN64
|
|
|
|
LARGE_INTEGER f;
|
|
|
|
QueryPerformanceFrequency(&f);
|
|
|
|
m_Frequency = f.QuadPart;
|
|
|
|
#endif
|
2023-06-29 12:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Lib::Timer::Start()
|
|
|
|
{
|
2023-06-29 12:20:34 +02:00
|
|
|
#ifdef _WIN64
|
|
|
|
LARGE_INTEGER c;
|
|
|
|
QueryPerformanceCounter(&c);
|
|
|
|
m_StartTime = c.QuadPart;
|
|
|
|
#endif
|
2023-06-29 12:31:07 +02:00
|
|
|
m_is_timer_paused = false;
|
2023-06-29 12:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Lib::Timer::Pause()
|
|
|
|
{
|
2023-06-29 12:20:34 +02:00
|
|
|
#ifdef _WIN64
|
|
|
|
LARGE_INTEGER c;
|
|
|
|
QueryPerformanceCounter(&c);
|
|
|
|
m_PauseTime = c.QuadPart;
|
|
|
|
#endif
|
|
|
|
m_is_timer_paused = true;
|
2023-06-29 12:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Lib::Timer::Resume()
|
|
|
|
{
|
2023-06-29 12:20:34 +02:00
|
|
|
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;
|
2023-06-29 12:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Lib::Timer::IsPaused() const
|
|
|
|
{
|
2023-06-29 12:20:34 +02:00
|
|
|
return m_is_timer_paused;
|
2023-06-29 12:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
double Lib::Timer::GetTimeMsec() const
|
|
|
|
{
|
2023-06-29 12:20:34 +02:00
|
|
|
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);
|
2023-06-29 12:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
double Lib::Timer::GetTimeSec() const
|
|
|
|
{
|
2023-06-29 12:20:34 +02:00
|
|
|
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);
|
2023-06-29 12:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 Lib::Timer::GetTicks() const
|
|
|
|
{
|
2023-06-29 12:20:34 +02:00
|
|
|
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);
|
2023-06-29 12:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 Lib::Timer::GetFrequency() const
|
|
|
|
{
|
2023-06-29 12:20:34 +02:00
|
|
|
return m_Frequency;
|
2023-06-29 12:17:05 +02:00
|
|
|
}
|
2023-06-29 12:20:34 +02:00
|
|
|
|