Made delay updates less erratic

This commit is contained in:
Edward Richardson 2014-08-19 22:30:33 +12:00
parent 6cd4fd8151
commit 4db8b3e421
4 changed files with 25 additions and 10 deletions

View File

@ -110,7 +110,7 @@ unsigned int lastrecvtime[MAXPLAYERS]; // [RH] Used for pings
unsigned int currrecvtime[MAXPLAYERS];
unsigned int lastglobalrecvtime; // Identify the last time a packet was recieved.
bool hadlate;
int netdelay[MAXNETNODES]; // Used for storing network delay times.
int netdelay[MAXNETNODES][BACKUPTICS]; // Used for storing network delay times.
int nodeforplayer[MAXPLAYERS];
int playerfornode[MAXNETNODES];
@ -803,7 +803,7 @@ void GetPackets (void)
}
// Pull current network delay from node
netdelay[netnode] = netbuffer[k++];
netdelay[netnode][(nettics[netnode]+1) % BACKUPTICS] = netbuffer[k++];
playerbytes[0] = netconsole;
if (netbuffer[0] & NCMD_MULTI)
@ -1340,7 +1340,15 @@ void NetUpdate (void)
// [ED850] It seems that there is a bias based on network adaption (which the arbitrator doesn't do),
// so I have set this up to assume one less tic, which appears to balance it out.
if (net_ticbalance)
average = ((netdelay[0] + ARBITRATOR_DELAY) / 2) - 1;
{
for (i = 0; i < BACKUPTICS; i++)
{
average += netdelay[nodeforplayer[Net_Arbitrator]][i];
}
average /= BACKUPTICS;
average = ((netdelay[0][nettics[0] % BACKUPTICS] + average) / 2) - 1;
}
mastertics = nettics[nodeforplayer[Net_Arbitrator]] + average;
}
if (nettics[0] <= mastertics)
@ -2750,7 +2758,6 @@ void Net_SkipCommand (int type, BYTE **stream)
CCMD (pings)
{
int i;
Printf("%d (%d ms) arbitrator buffer time\n", ARBITRATOR_DELAY * ticdup, (ARBITRATOR_DELAY * ticdup) * (1000 / TICRATE));
for (i = 0; i < MAXPLAYERS; i++)
if (playeringame[i])
Printf ("% 4d %s\n", currrecvtime[i] - lastrecvtime[i],

View File

@ -142,9 +142,8 @@ extern struct ticcmd_t localcmds[LOCALCMDTICS];
extern int maketic;
extern int nettics[MAXNETNODES];
extern int netdelay[MAXNETNODES];
extern int netdelay[MAXNETNODES][BACKUPTICS];
extern int nodeforplayer[MAXPLAYERS];
#define ARBITRATOR_DELAY netdelay[nodeforplayer[Net_Arbitrator]]
extern ticcmd_t netcmds[MAXPLAYERS][BACKUPTICS];
extern int ticdup;

View File

@ -934,9 +934,11 @@ static void DrawLatency()
{
return;
}
int localdelay = (netdelay[0] * ticdup) * (1000 / TICRATE);
int arbitratordelay = (ARBITRATOR_DELAY * ticdup) * (1000 / TICRATE);
int i, localdelay = 0, arbitratordelay = 0;
for (i = 0; i < BACKUPTICS; i++) localdelay += netdelay[0][i];
for (i = 0; i < BACKUPTICS; i++) arbitratordelay += netdelay[nodeforplayer[Net_Arbitrator]][i];
localdelay = ((localdelay / BACKUPTICS) * ticdup) * (1000 / TICRATE);
arbitratordelay = ((arbitratordelay / BACKUPTICS) * ticdup) * (1000 / TICRATE);
int color = CR_GREEN;
if (MAX(localdelay, arbitratordelay) > 200)
{

View File

@ -419,7 +419,14 @@ static void HU_DrawPlayer (player_t *player, bool highlight, int col1, int col2,
screen->DrawText (SmallFont, color, col4, y + ypadding, player->userinfo.GetName(),
DTA_CleanNoMove, true, TAG_DONE);
mysnprintf(str, countof(str), "%d", (netdelay[nodeforplayer[(int)(player - players)]] * ticdup) * (1000 / TICRATE));
int avgdelay = 0;
for (int i = 0; i < BACKUPTICS; i++)
{
avgdelay += netdelay[nodeforplayer[(int)(player - players)]][i];
}
avgdelay /= BACKUPTICS;
mysnprintf(str, countof(str), "%d", (avgdelay * ticdup) * (1000 / TICRATE));
screen->DrawText(SmallFont, color, col5, y + ypadding, str,
DTA_CleanNoMove, true, TAG_DONE);