mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-23 18:45:36 +00:00
linux timer implementation
This commit is contained in:
parent
f52b0ad01d
commit
42a73fad81
@ -2,6 +2,8 @@
|
||||
|
||||
#ifdef _WIN64
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <ctime>
|
||||
#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<double>(current_time - m_StartTime)) / static_cast<double>(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<double>(current_time - m_StartTime)) / static_cast<double>(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; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user