Final changes to balancing

This commit is contained in:
Edward Richardson 2014-09-26 15:37:14 +12:00
parent 8f82243f4c
commit 84cf799803

View file

@ -111,6 +111,7 @@ unsigned int currrecvtime[MAXPLAYERS];
unsigned int lastglobalrecvtime; // Identify the last time a packet was recieved. unsigned int lastglobalrecvtime; // Identify the last time a packet was recieved.
bool hadlate; bool hadlate;
int netdelay[MAXNETNODES][BACKUPTICS]; // Used for storing network delay times. int netdelay[MAXNETNODES][BACKUPTICS]; // Used for storing network delay times.
int lastaverage;
int nodeforplayer[MAXPLAYERS]; int nodeforplayer[MAXPLAYERS];
int playerfornode[MAXNETNODES]; int playerfornode[MAXNETNODES];
@ -1407,36 +1408,26 @@ void NetUpdate (void)
int totalavg = 0; int totalavg = 0;
if (net_ticbalance) if (net_ticbalance)
{ {
// We shouldn't adapt if we are already the slowest node, otherwise it just adds more latency // We shouldn't adapt if we are already the slower then the arbitrator, otherwise it just adds more latency
bool slow = true; int nodeavg = 0, arbavg = 0;
int nodeavg = 0;
for (i = 1; i < MAXNETNODES; i++)
{
if (!nodeingame[i])
continue;
if (netdelay[i][0] > netdelay[0][0]) for (j = 0; j < BACKUPTICS; j++)
{ {
slow = false; arbavg += netdelay[nodeforplayer[Net_Arbitrator]][j];
break; nodeavg += netdelay[0][j];
}
} }
arbavg /= BACKUPTICS;
nodeavg /= BACKUPTICS;
if (!slow) if (arbavg > nodeavg)
{ {
int totalnodes = 0; lastaverage = totalavg = ((arbavg + nodeavg) / 2);
for (i = 0; i < MAXNETNODES; i++) }
{ else
if (!nodeingame[i]) {
continue; if (nodeavg > (arbavg + 2) && lastaverage > 0)
lastaverage--;
totalnodes++; totalavg = lastaverage;
nodeavg = 0;
for (j = 0; j < BACKUPTICS; j++) nodeavg += netdelay[i][j];
totalavg += (nodeavg / BACKUPTICS);
}
totalavg = (totalavg / totalnodes) - 1;
} }
} }