Move rate limiting / queued packet sending logic from Com_Frame() to sv_main.c
This commit is contained in:
parent
58a5d3d383
commit
e6ba500164
6 changed files with 121 additions and 87 deletions
|
@ -50,6 +50,7 @@ cvar_t *sv_mapChecksum;
|
|||
cvar_t *sv_serverid;
|
||||
cvar_t *sv_minRate;
|
||||
cvar_t *sv_maxRate;
|
||||
cvar_t *sv_dlRate;
|
||||
cvar_t *sv_minPing;
|
||||
cvar_t *sv_maxPing;
|
||||
cvar_t *sv_gametype;
|
||||
|
@ -1205,3 +1206,83 @@ int SV_RateMsec(client_t *client)
|
|||
else
|
||||
return rateMsec - rate;
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
SV_SendQueuedPackets
|
||||
|
||||
Send download messages and queued packets in the time that we're idle, i.e.
|
||||
not computing a server frame or sending client snapshots.
|
||||
Return the time in msec until we expect to be called next
|
||||
====================
|
||||
*/
|
||||
|
||||
int SV_SendQueuedPackets()
|
||||
{
|
||||
int numBlocks;
|
||||
int dlStart, deltaT, delayT;
|
||||
static int dlNextRound = 0;
|
||||
int timeVal = INT_MAX;
|
||||
|
||||
// Send out fragmented packets now that we're idle
|
||||
delayT = SV_SendQueuedMessages();
|
||||
if(delayT >= 0)
|
||||
timeVal = delayT;
|
||||
|
||||
if(sv_dlRate->integer)
|
||||
{
|
||||
// Rate limiting. This is very imprecise for high
|
||||
// download rates due to millisecond timedelta resolution
|
||||
dlStart = Sys_Milliseconds();
|
||||
deltaT = dlNextRound - dlStart;
|
||||
|
||||
if(deltaT > 0)
|
||||
{
|
||||
if(deltaT < timeVal)
|
||||
timeVal = deltaT + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
numBlocks = SV_SendDownloadMessages();
|
||||
|
||||
if(numBlocks)
|
||||
{
|
||||
// There are active downloads
|
||||
deltaT = Sys_Milliseconds() - dlStart;
|
||||
|
||||
delayT = 1000 * numBlocks * MAX_DOWNLOAD_BLKSIZE;
|
||||
delayT /= sv_dlRate->integer * 1024;
|
||||
|
||||
if(delayT <= deltaT + 1)
|
||||
{
|
||||
// Sending the last round of download messages
|
||||
// took too long for given rate, don't wait for
|
||||
// next round, but always enforce a 1ms delay
|
||||
// between DL message rounds so we don't hog
|
||||
// all of the bandwidth. This will result in an
|
||||
// effective maximum rate of 1MB/s per user, but the
|
||||
// low download window size limits this anyways.
|
||||
if(timeVal > 2)
|
||||
timeVal = 2;
|
||||
|
||||
dlNextRound = dlStart + deltaT + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dlNextRound = dlStart + delayT;
|
||||
delayT -= deltaT;
|
||||
|
||||
if(delayT < timeVal)
|
||||
timeVal = delayT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(SV_SendDownloadMessages())
|
||||
timeVal = 0;
|
||||
}
|
||||
|
||||
return timeVal;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue