1
0
mirror of synced 2024-11-30 18:34:29 +01:00

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:
daver32 2024-05-01 20:48:41 +02:00 committed by GitHub
parent 1df0eea6c6
commit 6fbbf899b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -262,6 +262,13 @@ namespace hex {
const auto targetFrameTime = 1.0 / targetFPS; const auto targetFrameTime = 1.0 / targetFPS;
if (frameTime < targetFrameTime) { if (frameTime < targetFrameTime) {
glfwWaitEventsTimeout(targetFrameTime - frameTime); 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));
}
} }
} }
} }