Timer: Add ResetIfNPassed()

This commit is contained in:
Stenzek
2023-09-24 11:22:22 +10:00
committed by Connor McLaughlin
parent 5555e334af
commit 25a3ea98bc
2 changed files with 40 additions and 2 deletions
+35 -1
View File
@@ -1,5 +1,5 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2021 PCSX2 Dev Team
* Copyright (C) 2002-2023 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
@@ -163,4 +163,38 @@ namespace Common
m_tvStartValue = value;
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;
}
} // namespace Common
+5 -1
View File
@@ -1,5 +1,5 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2021 PCSX2 Dev Team
* Copyright (C) 2002-2023 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
@@ -46,6 +46,10 @@ namespace Common
double GetTimeMillisecondsAndReset();
double GetTimeNanosecondsAndReset();
bool ResetIfSecondsPassed(double s);
bool ResetIfMillisecondsPassed(double s);
bool ResetIfNanosecondsPassed(double s);
private:
Value m_tvStartValue;
};