readd seconds stuff

This commit is contained in:
Krzosa Karol
2025-01-05 10:23:41 +01:00
parent 489c8c413e
commit 67f654f72e
6 changed files with 55 additions and 22 deletions

View File

@@ -10,3 +10,16 @@ fn os_date_t os_local_time_now(void) {
result.year = lt->tm_year;
return result;
}
fn u64 os_get_microseconds(void) {
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
u64 result = t.tv_sec*million(1) + (t.tv_nsec/thousand(1));
return result;
}
fn f64 os_get_milliseconds(void) {
u64 micros = os_get_microseconds();
f64 result = (f64)micros / 1000.0;
return result;
}

View File

@@ -11,3 +11,23 @@ fn os_date_t os_local_time_now(void) {
result.year = lt.wYear;
return result;
}
fn f64 os_seconds_now(void) {
static int64_t counts_per_second;
if (counts_per_second == 0) {
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
counts_per_second = freq.QuadPart;
}
LARGE_INTEGER time;
QueryPerformanceCounter(&time);
f64 result = (f64)time.QuadPart / (f64)counts_per_second;
return result;
}
fn f64 os_get_milliseconds(void) {
f64 secs = os_seconds_now();
f64 result = secs * 1000;
return result;
}