diff --git a/src/Lib/Timer.cpp b/src/Lib/Timer.cpp index 3dd1d2513..bad8805ae 100644 --- a/src/Lib/Timer.cpp +++ b/src/Lib/Timer.cpp @@ -2,6 +2,8 @@ #ifdef _WIN64 #include +#else +#include #endif Lib::Timer::Timer() { @@ -10,7 +12,7 @@ Lib::Timer::Timer() { QueryPerformanceFrequency(&f); m_Frequency = f.QuadPart; #else -#error Unimplemented Timer constructor + m_Frequency = 1000000000LL; #endif } @@ -20,7 +22,9 @@ void Lib::Timer::Start() { QueryPerformanceCounter(&c); m_StartTime = c.QuadPart; #else -#error Unimplemented Timer::Start() + struct timespec now {}; + clock_gettime(CLOCK_MONOTONIC, &now); + m_StartTime = now.tv_sec* 1000000000LL + now.tv_nse #endif m_is_timer_paused = false; } @@ -31,7 +35,9 @@ void Lib::Timer::Pause() { QueryPerformanceCounter(&c); m_PauseTime = c.QuadPart; #else -#error Unimplemented Timer::Pause() + struct timespec now {}; + clock_gettime(CLOCK_MONOTONIC, &now); + m_PauseTime = now.tv_sec* 1000000000LL + now.tv_nse #endif m_is_timer_paused = true; } @@ -43,7 +49,9 @@ void Lib::Timer::Resume() { QueryPerformanceCounter(&c); current_time = c.QuadPart; #else -#error Unimplemented Timer::Resume() + struct timespec now {}; + clock_gettime(CLOCK_MONOTONIC, &now); + current_time = now.tv_sec* 1000000000LL + now.tv_nse #endif m_StartTime += current_time - m_PauseTime; m_is_timer_paused = false; @@ -62,7 +70,9 @@ double Lib::Timer::GetTimeMsec() const { QueryPerformanceCounter(&c); current_time = c.QuadPart; #else -#error Unimplemented Timer::GetTimeMsec() + struct timespec now {}; + clock_gettime(CLOCK_MONOTONIC, &now); + current_time = now.tv_sec * 1000000000LL + now.tv_nse #endif return 1000.0 * (static_cast(current_time - m_StartTime)) / static_cast(m_Frequency); } @@ -78,7 +88,9 @@ double Lib::Timer::GetTimeSec() const { QueryPerformanceCounter(&c); current_time = c.QuadPart; #else -#error Unimplemented Timer::GetTimeSec() + struct timespec now {}; + clock_gettime(CLOCK_MONOTONIC, &now); + current_time = now.tv_sec * 1000000000LL + now.tv_nse #endif return (static_cast(current_time - m_StartTime)) / static_cast(m_Frequency); } @@ -94,10 +106,11 @@ u64 Lib::Timer::GetTicks() const { QueryPerformanceCounter(&c); current_time = c.QuadPart; #else -#error Unimplemented Timer::GetTicks() + struct timespec now {}; + clock_gettime(CLOCK_MONOTONIC, &now); + current_time = now.tv_sec * 1000000000LL + now.tv_nse #endif return (current_time - m_StartTime); } u64 Lib::Timer::GetFrequency() const { return m_Frequency; } -