mirror of
https://github.com/korenkonder/ReDIVA.git
synced 2026-10-03 04:08:10 +03:00
40 lines
964 B
C++
40 lines
964 B
C++
/*
|
|
by korenkonder
|
|
GitHub/GitLab: korenkonder
|
|
*/
|
|
|
|
#include "time.hpp"
|
|
|
|
static double_t time_struct_get_freq();
|
|
|
|
time_struct::time_struct() : timestamp() {
|
|
get_timestamp();
|
|
inv_freq = time_struct_get_freq();
|
|
}
|
|
|
|
double_t time_struct::calc_time() {
|
|
LARGE_INTEGER timestamp;
|
|
if (QueryPerformanceCounter(×tamp))
|
|
return (double_t)(timestamp.QuadPart - this->timestamp.QuadPart) * inv_freq;
|
|
return 0.0;
|
|
}
|
|
|
|
int64_t time_struct::calc_time_int() {
|
|
LARGE_INTEGER timestamp;
|
|
if (QueryPerformanceCounter(×tamp))
|
|
return (int64_t)((double_t)(timestamp.QuadPart - this->timestamp.QuadPart) * inv_freq * 1000.0);
|
|
return 0;
|
|
}
|
|
|
|
void time_struct::get_timestamp() {
|
|
if (!QueryPerformanceCounter(×tamp))
|
|
timestamp.QuadPart = 0;
|
|
}
|
|
|
|
static double_t time_struct_get_freq() {
|
|
LARGE_INTEGER freq;
|
|
if (QueryPerformanceFrequency(&freq))
|
|
return 1000.0 / (double_t)freq.LowPart;
|
|
return 0.0;
|
|
}
|