Skip to content

Commit

Permalink
qcommon: never sleep with common.framerate.max -2
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Apr 26, 2024
1 parent 4588564 commit 3ab1ffc
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/engine/qcommon/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,8 @@ void Com_Frame()
Sys::Error( "Shutting down to prevent time overflow" );
}

bool sleep = true;

// we may want to spin here if things are going too fast
if ( !cvar_demo_timedemo.Get() )
{
Expand All @@ -907,11 +909,10 @@ void Com_Frame()
max = maxfps.Get();
}

// A positive maxfps caps the fps to the given number, with an implicit
// cap at 333fps to avoid bugs. Above 333fps minMsec is less than 3.
// At 1 or 2 minMsec, the game still runs but exhibits various issues
// such as first-person weapon model flickering, or client having
// connection issues with server.
/* A positive maxfps caps the fps to the given number, with an implicit
cap at 333fps to avoid bugs. Above 333fps minMsec is less than 3 and with
minMsec being 2 or less some variables may become zero and some code may
experience division by zero. */
if ( max > 0 )
{
minMsec = std::max( 1000 / max, 3 );
Expand All @@ -921,11 +922,18 @@ void Com_Frame()
{
minMsec = 3;
}
// A negative maxfps really unlocks fps (and bugs).
else
/* A negative maxfps unlocks fps more (and unfortunate bugs) but cap
it to 1000 (because of a remaining sleep it's a bit less than that). */
else if ( max == -1 )
{
minMsec = 1;
}
// A maxfps smaller than -1 unlocks all remaining fps (and expected bugs).
else
{
minMsec = 0;
sleep = false;
}
}
}
else
Expand All @@ -952,7 +960,11 @@ void Com_Frame()
while ( msec < minMsec )
{
//give cycles back to the OS
Sys::SleepFor(std::chrono::milliseconds(std::min(minMsec - msec, 50)));
if ( sleep )
{
Sys::SleepFor(std::chrono::milliseconds(std::min(minMsec - msec, 50)));
}

IN_Frame();

Com_EventLoop();
Expand Down

0 comments on commit 3ab1ffc

Please sign in to comment.