- Get rid of unused ShouldSkipDisplayingFrame
- Get rid of unused SetDisplayMaxFPS - Get rid of unused UsesLowerLeftOrigin - Get rid of unused GetWindowScale - Get rid of unused timer code + SleepUntil
This commit is contained in:
parent
e8273d964f
commit
22abea6fe8
5 changed files with 3 additions and 143 deletions
|
|
@ -15,23 +15,10 @@ namespace Common {
|
|||
#ifdef _WIN32
|
||||
|
||||
static double s_counter_frequency;
|
||||
static bool s_counter_initialized = false;
|
||||
|
||||
static HANDLE GetSleepTimer(void)
|
||||
{
|
||||
// This gets leaked... oh well.
|
||||
static thread_local HANDLE s_sleep_timer;
|
||||
static thread_local bool s_sleep_timer_created = false;
|
||||
if (s_sleep_timer_created)
|
||||
return s_sleep_timer;
|
||||
|
||||
s_sleep_timer_created = true;
|
||||
s_sleep_timer = CreateWaitableTimer(nullptr, TRUE, nullptr);
|
||||
return s_sleep_timer;
|
||||
}
|
||||
|
||||
Timer::Value Timer::GetValue(void)
|
||||
{
|
||||
static bool s_counter_initialized = false;
|
||||
// even if this races, it should still result in the same value..
|
||||
if (!s_counter_initialized)
|
||||
{
|
||||
|
|
@ -65,57 +52,7 @@ Timer::Value Timer::ConvertSecondsToValue(double s)
|
|||
{
|
||||
return static_cast<Value>((s * 1000000000.0) * s_counter_frequency);
|
||||
}
|
||||
|
||||
Timer::Value Timer::ConvertMillisecondsToValue(double ms)
|
||||
{
|
||||
return static_cast<Value>((ms * 1000000.0) * s_counter_frequency);
|
||||
}
|
||||
|
||||
Timer::Value Timer::ConvertNanosecondsToValue(double ns)
|
||||
{
|
||||
return static_cast<Value>(ns * s_counter_frequency);
|
||||
}
|
||||
|
||||
void Timer::SleepUntil(Value value, bool exact)
|
||||
{
|
||||
if (exact)
|
||||
{
|
||||
while (GetValue() < value)
|
||||
SleepUntil(value, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::int64_t diff = static_cast<std::int64_t>(value - GetValue());
|
||||
if (diff <= 0)
|
||||
return;
|
||||
|
||||
#ifndef _UWP
|
||||
HANDLE timer = GetSleepTimer();
|
||||
if (timer)
|
||||
{
|
||||
FILETIME ft;
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
|
||||
LARGE_INTEGER fti;
|
||||
fti.LowPart = ft.dwLowDateTime;
|
||||
fti.HighPart = ft.dwHighDateTime;
|
||||
fti.QuadPart += diff;
|
||||
|
||||
if (SetWaitableTimer(timer, &fti, 0, nullptr, nullptr, FALSE))
|
||||
{
|
||||
WaitForSingleObject(timer, INFINITE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// falling back to sleep... bad.
|
||||
Sleep(static_cast<DWORD>(static_cast<std::uint64_t>(diff) / 1000000));
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
Timer::Value Timer::GetValue(void)
|
||||
{
|
||||
struct timespec tv;
|
||||
|
|
@ -142,46 +79,6 @@ Timer::Value Timer::ConvertSecondsToValue(double s)
|
|||
{
|
||||
return static_cast<Value>(s * 1000000000.0);
|
||||
}
|
||||
|
||||
Timer::Value Timer::ConvertMillisecondsToValue(double ms)
|
||||
{
|
||||
return static_cast<Value>(ms * 1000000.0);
|
||||
}
|
||||
|
||||
Timer::Value Timer::ConvertNanosecondsToValue(double ns)
|
||||
{
|
||||
return static_cast<Value>(ns);
|
||||
}
|
||||
|
||||
void Timer::SleepUntil(Value value, bool exact)
|
||||
{
|
||||
if (exact)
|
||||
{
|
||||
while (GetValue() < value)
|
||||
SleepUntil(value, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Apple doesn't have TIMER_ABSTIME, so fall back to nanosleep in such a case.
|
||||
#ifdef __APPLE__
|
||||
const Value current_time = GetValue();
|
||||
if (value <= current_time)
|
||||
return;
|
||||
|
||||
const Value diff = value - current_time;
|
||||
struct timespec ts;
|
||||
ts.tv_sec = diff / UINT64_C(1000000000);
|
||||
ts.tv_nsec = diff % UINT64_C(1000000000);
|
||||
nanosleep(&ts, nullptr);
|
||||
#else
|
||||
struct timespec ts;
|
||||
ts.tv_sec = value / UINT64_C(1000000000);
|
||||
ts.tv_nsec = value % UINT64_C(1000000000);
|
||||
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, nullptr);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Timer::Timer()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue