2023-08-06 08:48:11 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-08-04 11:32:28 -04:00
|
|
|
#include <cstdint>
|
|
|
|
|
2022-04-14 19:00:42 -04:00
|
|
|
#if defined(MACOS)
|
2023-10-12 23:44:43 -04:00
|
|
|
#include <mach/mach_time.h>
|
|
|
|
#include <sys/sysctl.h>
|
2022-04-14 19:00:42 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(WIN32)
|
2023-10-12 23:44:43 -04:00
|
|
|
#include <windows.h>
|
2022-04-14 19:00:42 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MACOS)
|
|
|
|
// from XIV-on-Mac, I think it changed in recent Wine versions?
|
2023-10-12 23:44:43 -04:00
|
|
|
uint32_t TickCount()
|
|
|
|
{
|
2022-04-14 19:00:42 -04:00
|
|
|
struct mach_timebase_info timebase;
|
|
|
|
mach_timebase_info(&timebase);
|
|
|
|
|
|
|
|
auto machtime = mach_continuous_time();
|
2023-10-12 23:44:43 -04:00
|
|
|
auto numer = uint64_t(timebase.numer);
|
2022-04-14 19:00:42 -04:00
|
|
|
auto denom = uint64_t(timebase.denom);
|
|
|
|
auto monotonic_time = machtime * numer / denom / 100;
|
|
|
|
return monotonic_time / 10000;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(LINUX)
|
2022-08-04 11:32:28 -04:00
|
|
|
#include <ctime>
|
|
|
|
|
2023-10-12 23:44:43 -04:00
|
|
|
uint32_t TickCount()
|
|
|
|
{
|
2022-04-14 19:00:42 -04:00
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
|
|
|
|
return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(WIN32)
|
2023-10-12 23:44:43 -04:00
|
|
|
uint32_t TickCount()
|
|
|
|
{
|
2022-04-14 19:00:42 -04:00
|
|
|
return GetTickCount();
|
|
|
|
}
|
|
|
|
#endif
|