mirror of https://github.com/AxioDL/metaforce.git
Adopt JBus' GetGCTicks()
This commit is contained in:
parent
5c0443d160
commit
ef43c3319b
|
@ -30,7 +30,7 @@ struct OSCalendarTime
|
|||
class CBasics
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Initialize();
|
||||
static const char* Stringize(const char* fmt, ...);
|
||||
|
||||
static const u64 SECONDS_TO_2000;
|
||||
|
@ -40,6 +40,7 @@ public:
|
|||
static std::chrono::system_clock::time_point FromWiiTime(OSTime wiiTime);
|
||||
|
||||
static u64 GetGCTicks();
|
||||
static constexpr u64 GetGCTicksPerSec() { return 486000000ull; }
|
||||
|
||||
static OSCalendarTime ToCalendarTime(OSTime time) { return ToCalendarTime(FromWiiTime(time)); }
|
||||
static OSCalendarTime ToCalendarTime(std::chrono::system_clock::time_point time);
|
||||
|
|
|
@ -1,14 +1,42 @@
|
|||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#if __APPLE__
|
||||
#include <mach/mach_time.h>
|
||||
#endif
|
||||
#else
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "CBasics.hpp"
|
||||
|
||||
#if __APPLE__
|
||||
static u64 MachToDolphinNum;
|
||||
static u64 MachToDolphinDenom;
|
||||
#elif _WIN32
|
||||
static LARGE_INTEGER PerfFrequency;
|
||||
#endif
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
void CBasics::Init()
|
||||
void CBasics::Initialize()
|
||||
{
|
||||
#if __APPLE__
|
||||
mach_timebase_info_data_t timebase;
|
||||
mach_timebase_info(&timebase);
|
||||
MachToDolphinNum = GetGCTicksPerSec() * timebase.numer;
|
||||
MachToDolphinDenom = 1000000000ull * timebase.denom;
|
||||
#elif _WIN32
|
||||
QueryPerformanceFrequency(&PerfFrequency);
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* CBasics::Stringize(const char* fmt, ...)
|
||||
|
@ -23,9 +51,22 @@ const char* CBasics::Stringize(const char* fmt, ...)
|
|||
|
||||
u64 CBasics::GetGCTicks()
|
||||
{
|
||||
auto nanos = std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||
return nanos * 486000000 / 1000000000;
|
||||
#if __APPLE__
|
||||
return mach_absolute_time() * MachToDolphinNum / MachToDolphinDenom;
|
||||
#elif __linux__ || __FreeBSD__
|
||||
struct timespec tp;
|
||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||
|
||||
return u64((tp.tv_sec * 1000000000ull) + tp.tv_nsec) * GetGCTicksPerSec() / 1000000000ull;
|
||||
#elif _WIN32
|
||||
LARGE_INTEGER perf;
|
||||
QueryPerformanceCounter(&perf);
|
||||
perf.QuadPart *= GetGCTicksPerSec();
|
||||
perf.QuadPart /= PerfFrequency.QuadPart;
|
||||
return perf.QuadPart;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
const u64 CBasics::SECONDS_TO_2000 = 946684800LL;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "Graphics/Shaders/CXRayBlurFilter.hpp"
|
||||
#include "Character/CCharLayoutInfo.hpp"
|
||||
#include "CGBASupport.hpp"
|
||||
#include "CBasics.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
@ -114,6 +115,7 @@ void CMain::ResetGameState()
|
|||
|
||||
void CMain::InitializeSubsystems(const hecl::Runtime::FileStoreManager& storeMgr)
|
||||
{
|
||||
CBasics::Initialize();
|
||||
CModelShaders::Initialize(storeMgr, CGraphics::g_BooFactory);
|
||||
CMoviePlayer::Initialize();
|
||||
CLineRenderer::Initialize();
|
||||
|
|
Loading…
Reference in New Issue