fix: Frame rate getting unlocked when inputs are being processed (#1632)
### Problem description The framerate limiter doesn't work when inputs are being sent (eg mouse cursor moving over the window), because `glfwWaitEventsTimeout` returns early when it encounters an event. ### Implementation description I made it sleep for the remaining time when that happens.
This commit is contained in:
parent
1df0eea6c6
commit
6fbbf899b0
@ -262,6 +262,13 @@ namespace hex {
|
||||
const auto targetFrameTime = 1.0 / targetFPS;
|
||||
if (frameTime < targetFrameTime) {
|
||||
glfwWaitEventsTimeout(targetFrameTime - frameTime);
|
||||
|
||||
// glfwWaitEventsTimeout might return early if there's an event
|
||||
const auto frameTime = glfwGetTime() - m_lastStartFrameTime;
|
||||
if (frameTime < targetFrameTime) {
|
||||
const auto timeToSleepMs = (int)((targetFrameTime - frameTime) * 1000);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(timeToSleepMs));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user