mirror of
https://github.com/UberGames/lilium-voyager.git
synced 2024-12-13 21:51:09 +00:00
Make NET_Sleep wait 1ms less than requested, then busy-wait the last ms for better timeout precision.
This commit is contained in:
parent
ccd24cd647
commit
34e0a6c6f6
2 changed files with 11 additions and 23 deletions
|
@ -2907,7 +2907,7 @@ void Com_Frame( void ) {
|
||||||
|
|
||||||
int msec, minMsec;
|
int msec, minMsec;
|
||||||
int timeVal;
|
int timeVal;
|
||||||
static int lastTime = 0;
|
static int lastTime = 0, bias = 0;
|
||||||
|
|
||||||
int timeBeforeFirstEvents;
|
int timeBeforeFirstEvents;
|
||||||
int timeBeforeServer;
|
int timeBeforeServer;
|
||||||
|
@ -2953,18 +2953,14 @@ void Com_Frame( void ) {
|
||||||
minMsec = 1;
|
minMsec = 1;
|
||||||
|
|
||||||
timeVal = com_frameTime - lastTime;
|
timeVal = com_frameTime - lastTime;
|
||||||
if(timeVal > minMsec)
|
bias += timeVal - minMsec;
|
||||||
{
|
|
||||||
// Adjust minMsec if previous frame took too long to render so
|
|
||||||
// that framerate is stable at the requested value.
|
|
||||||
timeVal -= minMsec;
|
|
||||||
|
|
||||||
if(timeVal > minMsec)
|
|
||||||
minMsec = 0;
|
|
||||||
else
|
|
||||||
minMsec -= timeVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(bias > minMsec)
|
||||||
|
bias = minMsec;
|
||||||
|
|
||||||
|
// Adjust minMsec if previous frame took too long to render so
|
||||||
|
// that framerate is stable at the requested value.
|
||||||
|
minMsec -= bias;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2973,10 +2969,11 @@ void Com_Frame( void ) {
|
||||||
timeVal = 0;
|
timeVal = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(com_busyWait->integer)
|
// Busy sleep the last millisecond for better timeout precision
|
||||||
|
if(com_busyWait->integer || timeVal < 2)
|
||||||
NET_Sleep(0);
|
NET_Sleep(0);
|
||||||
else
|
else
|
||||||
NET_Sleep(timeVal);
|
NET_Sleep(timeVal - 1);
|
||||||
|
|
||||||
msec = Sys_Milliseconds() - com_frameTime;
|
msec = Sys_Milliseconds() - com_frameTime;
|
||||||
|
|
||||||
|
|
|
@ -1707,18 +1707,9 @@ void NET_Sleep(int msec)
|
||||||
if(highestfd < 0)
|
if(highestfd < 0)
|
||||||
{
|
{
|
||||||
// windows ain't happy when select is called without valid FDs
|
// windows ain't happy when select is called without valid FDs
|
||||||
|
|
||||||
if(msec > 0)
|
|
||||||
msec--;
|
|
||||||
|
|
||||||
SleepEx(msec, 0);
|
SleepEx(msec, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TVW32_BIAS 999
|
|
||||||
// windows adds a whole millisecond of latency, otherwise granularity seems to be fine.
|
|
||||||
if(timeout.tv_usec > TVW32_BIAS)
|
|
||||||
timeout.tv_usec -= TVW32_BIAS;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
retval = select(highestfd + 1, &fdr, NULL, NULL, &timeout);
|
retval = select(highestfd + 1, &fdr, NULL, NULL, &timeout);
|
||||||
|
|
Loading…
Reference in a new issue