diff --git a/src/Lib/Timer.cpp b/src/Lib/Timer.cpp index e07ff73d..39ae829b 100644 --- a/src/Lib/Timer.cpp +++ b/src/Lib/Timer.cpp @@ -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(m_PauseTime - m_StartTime)) / static_cast(m_Frequency); + } + + u64 current_time = 0; + +#ifdef _WIN64 + LARGE_INTEGER c; + QueryPerformanceCounter(&c); + current_time = c.QuadPart; +#endif + + return 1000.0 * (static_cast(current_time - m_StartTime)) / static_cast(m_Frequency); } double Lib::Timer::GetTimeSec() const { - return 0.0; + if (m_is_timer_paused) + { + return (static_cast(m_PauseTime - m_StartTime)) / static_cast(m_Frequency); + } + + u64 current_time = 0; + +#ifdef _WIN64 + LARGE_INTEGER c; + QueryPerformanceCounter(&c); + current_time = c.QuadPart; +#endif + + return (static_cast(current_time - m_StartTime)) / static_cast(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; } +