mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 21:01:37 +00:00
Redo frame limiter logic to fix drifting.
This commit is contained in:
parent
42f808c926
commit
5ed5ff7ff0
2 changed files with 7 additions and 5 deletions
|
|
@ -10,18 +10,21 @@ void FrameLimiter::execute(int64_t fps)
|
|||
{
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
auto next = start + frame * 1000000000ns / fps;
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
|
||||
if (next > now && (next - now) < (2000000000ns / fps))
|
||||
if (now < next)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::floor<std::chrono::milliseconds>(next - now - 1ms));
|
||||
|
||||
while ((now = std::chrono::steady_clock::now()) < next)
|
||||
std::this_thread::yield();
|
||||
}
|
||||
else
|
||||
{
|
||||
next = now;
|
||||
}
|
||||
|
||||
frame = std::chrono::nanoseconds(std::chrono::steady_clock::now() - start).count() * fps / 1000000000ll + 1;
|
||||
next += 1000000000ns / fps;
|
||||
}
|
||||
|
||||
static FrameLimiter g_frameLimiter;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
struct FrameLimiter
|
||||
{
|
||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||
int64_t frame = 0;
|
||||
std::chrono::steady_clock::time_point next;
|
||||
|
||||
void execute(int64_t fps);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue