From dd700d185b67a42d98e6f1d5fe6e1e6e7726e974 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 16 May 2024 23:33:31 +0200 Subject: [PATCH] small accommodation --- src/engine/qcommon/common.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/engine/qcommon/common.cpp b/src/engine/qcommon/common.cpp index b29b1d1305..9fdfe292ef 100644 --- a/src/engine/qcommon/common.cpp +++ b/src/engine/qcommon/common.cpp @@ -873,11 +873,15 @@ void Com_Frame() msec = com_frameTime - lastTime; + // For framerates up to 250fps, sleep until 1ms is remaining + // use extra margin of 2ms when looking for an higher framerate. + int margin = minMsec > 3 ? 1 : 2; + while ( msec < minMsec ) { // Never sleep more than 50ms. - // Never sleep when there is 2ms or less remaining. - int sleep = std::max( std::min( minMsec - msec, 50 ) - 2, 0 ); + // Never sleep when there is only “margin” left or less remaining. + int sleep = std::max( std::min( minMsec - msec, 50 ) - margin, 0 ); if ( sleep ) {