mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-25 15:15:40 +00:00
Common: Add Timer::ResetIfNPassed()
This commit is contained in:
parent
9855a222e0
commit
1ba32585df
|
@ -288,6 +288,39 @@ double Timer::GetTimeNanosecondsAndReset()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Timer::ResetIfSecondsPassed(double s)
|
||||||
|
{
|
||||||
|
const Value value = GetCurrentValue();
|
||||||
|
const double ret = ConvertValueToSeconds(value - m_tvStartValue);
|
||||||
|
if (ret < s)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_tvStartValue = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Timer::ResetIfMillisecondsPassed(double s)
|
||||||
|
{
|
||||||
|
const Value value = GetCurrentValue();
|
||||||
|
const double ret = ConvertValueToMilliseconds(value - m_tvStartValue);
|
||||||
|
if (ret < s)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_tvStartValue = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Timer::ResetIfNanosecondsPassed(double s)
|
||||||
|
{
|
||||||
|
const Value value = GetCurrentValue();
|
||||||
|
const double ret = ConvertValueToNanoseconds(value - m_tvStartValue);
|
||||||
|
if (ret < s)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_tvStartValue = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Timer::BusyWait(std::uint64_t ns)
|
void Timer::BusyWait(std::uint64_t ns)
|
||||||
{
|
{
|
||||||
const Value start = GetCurrentValue();
|
const Value start = GetCurrentValue();
|
||||||
|
|
|
@ -40,6 +40,10 @@ public:
|
||||||
double GetTimeMillisecondsAndReset();
|
double GetTimeMillisecondsAndReset();
|
||||||
double GetTimeNanosecondsAndReset();
|
double GetTimeNanosecondsAndReset();
|
||||||
|
|
||||||
|
bool ResetIfSecondsPassed(double s);
|
||||||
|
bool ResetIfMillisecondsPassed(double s);
|
||||||
|
bool ResetIfNanosecondsPassed(double s);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Value m_tvStartValue;
|
Value m_tvStartValue;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue