2012-03-24 23:39:19 +01:00
|
|
|
#pragma once
|
2023-08-02 23:52:46 +02:00
|
|
|
#include <cstdint>
|
|
|
|
|
2024-07-26 11:16:41 +02:00
|
|
|
void TimeInit();
|
|
|
|
|
2012-03-24 23:39:19 +01:00
|
|
|
// Seconds.
|
|
|
|
double time_now_d();
|
|
|
|
|
2023-08-02 23:52:46 +02:00
|
|
|
// Raw time in nanoseconds.
|
|
|
|
// The only intended use is to match the timings from VK_GOOGLE_display_timing.
|
|
|
|
uint64_t time_now_raw();
|
|
|
|
|
2023-08-03 11:11:16 +02:00
|
|
|
// This is only interesting for Linux, in relation to VK_GOOGLE_display_timing.
|
|
|
|
double from_time_raw(uint64_t raw_time);
|
2023-08-03 12:59:25 +02:00
|
|
|
double from_time_raw_relative(uint64_t raw_time);
|
2023-08-03 11:11:16 +02:00
|
|
|
|
2023-11-20 11:46:36 +01:00
|
|
|
// Seconds, Unix UTC time
|
|
|
|
double time_now_unix_utc();
|
|
|
|
|
2012-03-31 11:16:13 +02:00
|
|
|
// Sleep. Does not necessarily have millisecond granularity, especially on Windows.
|
2012-03-24 23:39:19 +01:00
|
|
|
void sleep_ms(int ms);
|
2020-10-05 20:58:33 +02:00
|
|
|
|
2024-07-26 11:16:41 +02:00
|
|
|
// Precise sleep. Can consume a little bit of CPU on Windows at least.
|
|
|
|
void sleep_precise(double seconds);
|
|
|
|
|
2023-08-07 21:38:03 +02:00
|
|
|
// Yield. Signals that this thread is busy-waiting but wants to allow other hyperthreads to run.
|
|
|
|
void yield();
|
|
|
|
|
2024-06-05 10:28:49 +02:00
|
|
|
void GetCurrentTimeFormatted(char formattedTime[13]);
|
2022-04-08 11:55:49 +02:00
|
|
|
|
2024-07-26 11:16:41 +02:00
|
|
|
// Most accurate timer possible - no extra double conversions. Only for spans.
|
2022-04-08 11:55:49 +02:00
|
|
|
class Instant {
|
|
|
|
public:
|
|
|
|
static Instant Now() {
|
2024-07-26 11:16:41 +02:00
|
|
|
return Instant();
|
2022-04-08 11:55:49 +02:00
|
|
|
}
|
2024-06-05 10:29:04 +02:00
|
|
|
double ElapsedSeconds() const;
|
|
|
|
int64_t ElapsedNanos() const;
|
|
|
|
private:
|
2024-07-26 11:16:41 +02:00
|
|
|
Instant();
|
2024-06-05 10:29:04 +02:00
|
|
|
uint64_t nativeStart_;
|
|
|
|
#ifndef _WIN32
|
|
|
|
int64_t nsecs_;
|
|
|
|
#endif
|
|
|
|
};
|