]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
rewrote netgraph code
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 17 Sep 2009 16:42:55 +0000 (16:42 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 17 Sep 2009 16:42:55 +0000 (16:42 +0000)
netgraph now uses line graph (doesn't look very good though)
netgraph now shows last 4 seconds (rather than 100 packets)
netgraph now shows rate estimate

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9209 d7cf8633-e32d-0410-b094-e92efae38249

cl_input.c
cl_screen.c
host_cmd.c
netconn.c
netconn.h

index 00c0bed932af9ad077853354c8fc1f34e0f9f5ff..ae2562e63e98cbf30ba811f9e368f35c2d27570b 100644 (file)
@@ -1738,7 +1738,7 @@ void CL_SendMove(void)
                        MSG_WriteByte(&buf, 0);
                        // packet loss percentage
                        for (j = 0, packetloss = 0;j < NETGRAPH_PACKETS;j++)
-                               if (cls.netcon->incoming_unreliablesize[j] == NETGRAPH_LOSTPACKET)
+                               if (cls.netcon->incoming_netgraph[j].unreliablebytes == NETGRAPH_LOSTPACKET)
                                        packetloss++;
                        packetloss = packetloss * 100 / NETGRAPH_PACKETS;
                        MSG_WriteByte(&buf, packetloss);
index 4144b5953719aa6b32992ac5ed10b13794af55e4..4e5fd3de0ff41be7c420aabbcc556997da310567 100644 (file)
@@ -198,86 +198,67 @@ void SCR_CheckDrawCenterString (void)
        SCR_DrawCenterString ();
 }
 
-void SCR_DrawNetGraph_DrawGraph (int graphx, int graphy, int barwidth, int barheight, int bardivide, const char *label, float textsize, int packetcounter, int numparameters, const int **parameters, const float parametercolors[][4])
+void SCR_DrawNetGraph_DrawGraph (int graphx, int graphy, int graphwidth, int graphheight, float graphscale, const char *label, float textsize, int packetcounter, netgraphitem_t *netgraph)
 {
-       int j, k, x, y, index, offset, height;
+       netgraphitem_t *graph;
+       int j, x, y;
+       int totalbytes = 0;
+       char bytesstring[128];
+       float g[NETGRAPH_PACKETS][6];
+       float *a;
+       float *b;
+       DrawQ_Fill(graphx, graphy, graphwidth, graphheight + textsize * 2, 0, 0, 0, 0.5, 0);
        // draw the bar graph itself
        // advance the packet counter because it is the latest packet column being
        // built up and should come last
        packetcounter = (packetcounter + 1) % NETGRAPH_PACKETS;
+       memset(g, 0, sizeof(g));
        for (j = 0;j < NETGRAPH_PACKETS;j++)
        {
-               x = graphx + j * barwidth;
-               y = graphy + barheight;
-               index = (packetcounter + j) % NETGRAPH_PACKETS;
-               if (parameters[0][index] == NETGRAPH_LOSTPACKET)
-                       DrawQ_Fill(x, y - barheight, barwidth, barheight, 1, 0, 0, 1, 0);
-               else if (parameters[0][index] == NETGRAPH_CHOKEDPACKET)
-                       DrawQ_Fill(x, y - min(2, barheight), barwidth, min(2, barheight), 1, 1, 0, 1, 0);
+               graph = netgraph + j;
+               g[j][0] = 1.0f - 0.25f * (realtime - graph->time);
+               g[j][1] = 1.0f;
+               g[j][2] = 1.0f;
+               g[j][3] = 1.0f;
+               g[j][4] = 1.0f;
+               g[j][5] = 1.0f;
+               if (graph->unreliablebytes == NETGRAPH_LOSTPACKET)
+                       g[j][1] = 0.00f;
+               else if (graph->unreliablebytes == NETGRAPH_CHOKEDPACKET)
+                       g[j][2] = 0.96f;
                else
                {
-                       offset = 0;
-                       for (k = 0;k < numparameters;k++)
-                       {
-                               height = (parameters[k][index] + bardivide - 1) / bardivide;
-                               height = min(height, barheight - offset);
-                               offset += height;
-                               if (height)
-                                       DrawQ_Fill(x, y - offset, barwidth, height, parametercolors[k][0], parametercolors[k][1], parametercolors[k][2], parametercolors[k][3], 0);
-                       }
+                       g[j][3] = 1.0f    - graph->unreliablebytes * graphscale;
+                       g[j][4] = g[j][3] - graph->reliablebytes   * graphscale;
+                       g[j][5] = g[j][4] - graph->ackbytes        * graphscale;
+                       // count bytes in the last second
+                       if (realtime - graph->time < 1.0f)
+                               totalbytes += graph->unreliablebytes + graph->reliablebytes + graph->ackbytes;
                }
+               g[j][1] = bound(0.0f, g[j][1], 1.0f);
+               g[j][2] = bound(0.0f, g[j][2], 1.0f);
+               g[j][3] = bound(0.0f, g[j][3], 1.0f);
+               g[j][4] = bound(0.0f, g[j][4], 1.0f);
+               g[j][5] = bound(0.0f, g[j][5], 1.0f);
        }
-}
-
-const float netgraphcolors[3][4] =
-{
-       {1  , 0.5, 0  , 1},
-       {1  , 1  , 1  , 1},
-       {0  , 1  , 0  , 1},
-};
-
-void SCR_DrawNetGraph_DrawConnection_Client (netconn_t *conn, int graphx, int graphy, int barwidth, int barheight, int bardivide, const char *labelincoming, int separator, const char *labeloutgoing, float textsize)
-{
-       int numparameters;
-       const int *parameters[3];
-       // dim background
-       DrawQ_Fill(graphx                                          , graphy, barwidth * NETGRAPH_PACKETS, barheight + textsize, 0, 0, 0, 0.5, 0);
-       DrawQ_Fill(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy, barwidth * NETGRAPH_PACKETS, barheight + textsize, 0, 0, 0, 0.5, 0);
-       // draw the bar graphs
-       numparameters = 3;
-       parameters[0] = conn->incoming_unreliablesize;
-       parameters[1] = conn->incoming_reliablesize;
-       parameters[2] = conn->incoming_acksize;
-       SCR_DrawNetGraph_DrawGraph(graphx, graphy, barwidth, barheight, bardivide, labelincoming, textsize, conn->incoming_packetcounter, numparameters, parameters, netgraphcolors);
-       parameters[0] = conn->outgoing_unreliablesize;
-       parameters[1] = conn->outgoing_reliablesize;
-       parameters[2] = conn->outgoing_acksize;
-       SCR_DrawNetGraph_DrawGraph(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy, barwidth, barheight, bardivide, labeloutgoing, textsize, conn->outgoing_packetcounter, numparameters, parameters, netgraphcolors);
-       // draw labels
-       DrawQ_String(graphx                                          , graphy + barheight, labelincoming, 0, textsize, textsize, 1, 1, 1, 1, 0, NULL, false);
-       DrawQ_String(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy + barheight, labeloutgoing, 0, textsize, textsize, 1, 1, 1, 1, 0, NULL, false);
-}
-
-void SCR_DrawNetGraph_DrawConnection_Server (netconn_t *conn, int graphx, int graphy, int barwidth, int barheight, int bardivide, const char *labeloutgoing, int separator, const char *labelincoming, float textsize)
-{
-       int numparameters;
-       const int *parameters[3];
-       // dim background
-       DrawQ_Fill(graphx                                          , graphy, barwidth * NETGRAPH_PACKETS, barheight + textsize, 0, 0, 0, 0.5, 0);
-       DrawQ_Fill(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy, barwidth * NETGRAPH_PACKETS, barheight + textsize, 0, 0, 0, 0.5, 0);
-       // draw the bar graphs
-       numparameters = 3;
-       parameters[0] = conn->outgoing_unreliablesize;
-       parameters[1] = conn->outgoing_reliablesize;
-       parameters[2] = conn->outgoing_acksize;
-       SCR_DrawNetGraph_DrawGraph(graphx                                          , graphy, barwidth, barheight, bardivide, labeloutgoing, textsize, conn->outgoing_packetcounter, numparameters, parameters, netgraphcolors);
-       parameters[0] = conn->incoming_unreliablesize;
-       parameters[1] = conn->incoming_reliablesize;
-       parameters[2] = conn->incoming_acksize;
-       SCR_DrawNetGraph_DrawGraph(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy, barwidth, barheight, bardivide, labelincoming, textsize, conn->incoming_packetcounter, numparameters, parameters, netgraphcolors);
-       // draw labels
-       DrawQ_String(graphx                                          , graphy + barheight, labeloutgoing, 0, textsize, textsize, 1, 1, 1, 1, 0, NULL, false);
-       DrawQ_String(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy + barheight, labelincoming, 0, textsize, textsize, 1, 1, 1, 1, 0, NULL, false);
+       // render the lines for the graph
+       for (j = 0;j < NETGRAPH_PACKETS;j++)
+       {
+               a = g[j];
+               b = g[(j+1)%NETGRAPH_PACKETS];
+               if (a[0] < 0.0f || b[0] > 1.0f || b[0] < a[0])
+                       continue;
+               DrawQ_Line(0.0f, graphx + graphwidth * a[0], graphy + graphheight * a[2], graphx + graphwidth * b[0], graphy + graphheight * b[2], 1.0f, 1.0f, 0.0f, 1.0f, 0);
+               DrawQ_Line(0.0f, graphx + graphwidth * a[0], graphy + graphheight * a[1], graphx + graphwidth * b[0], graphy + graphheight * b[1], 1.0f, 0.0f, 0.0f, 1.0f, 0);
+               DrawQ_Line(0.0f, graphx + graphwidth * a[0], graphy + graphheight * a[5], graphx + graphwidth * b[0], graphy + graphheight * b[5], 0.0f, 1.0f, 0.0f, 1.0f, 0);
+               DrawQ_Line(0.0f, graphx + graphwidth * a[0], graphy + graphheight * a[4], graphx + graphwidth * b[0], graphy + graphheight * b[4], 1.0f, 1.0f, 1.0f, 1.0f, 0);
+               DrawQ_Line(0.0f, graphx + graphwidth * a[0], graphy + graphheight * a[3], graphx + graphwidth * b[0], graphy + graphheight * b[3], 1.0f, 0.5f, 0.0f, 1.0f, 0);
+       }
+       x = graphx;
+       y = graphy + graphheight;
+       dpsnprintf(bytesstring, sizeof(bytesstring), "%i", totalbytes);
+       DrawQ_String(x, y, label      , 0, textsize, textsize, 1.0f, 1.0f, 1.0f, 1.0f, 0, NULL, false);y += textsize;
+       DrawQ_String(x, y, bytesstring, 0, textsize, textsize, 1.0f, 1.0f, 1.0f, 1.0f, 0, NULL, false);y += textsize;
 }
 
 /*
@@ -287,7 +268,9 @@ SCR_DrawNetGraph
 */
 void SCR_DrawNetGraph (void)
 {
-       int i, separator1, separator2, barwidth, barheight, bardivide, netgraph_x, netgraph_y, textsize, index, netgraphsperrow;
+       int i, separator1, separator2, graphwidth, graphheight, netgraph_x, netgraph_y, textsize, index, netgraphsperrow;
+       float graphscale;
+       netconn_t *c;
 
        if (cls.state != ca_connected)
                return;
@@ -299,28 +282,32 @@ void SCR_DrawNetGraph (void)
        separator1 = 2;
        separator2 = 4;
        textsize = 8;
-       barwidth = 1;
-       barheight = 50;
-       bardivide = 20;
+       graphwidth = 120;
+       graphheight = 70;
+       graphscale = 1.0f / 1500.0f;
 
-       netgraphsperrow = (vid_conwidth.integer + separator2) / (barwidth * NETGRAPH_PACKETS * 2 + separator1 + separator2);
+       netgraphsperrow = (vid_conwidth.integer + separator2) / (graphwidth * 2 + separator1 + separator2);
        netgraphsperrow = max(netgraphsperrow, 1);
 
        index = 0;
-       netgraph_x = (vid_conwidth.integer + separator2) - (1 + (index % netgraphsperrow)) * (barwidth * NETGRAPH_PACKETS * 2 + separator1 + separator2);
-       netgraph_y = (vid_conheight.integer - 48 - sbar_info_pos.integer + separator2) - (1 + (index / netgraphsperrow)) * (barheight + textsize + separator2);
-       SCR_DrawNetGraph_DrawConnection_Client(cls.netcon, netgraph_x, netgraph_y, barwidth, barheight, bardivide, "incoming", separator1, "outgoing", textsize);
+       netgraph_x = (vid_conwidth.integer + separator2) - (1 + (index % netgraphsperrow)) * (graphwidth * 2 + separator1 + separator2);
+       netgraph_y = (vid_conheight.integer - 48 - sbar_info_pos.integer + separator2) - (1 + (index / netgraphsperrow)) * (graphheight + textsize + separator2);
+       c = cls.netcon;
+       SCR_DrawNetGraph_DrawGraph(netgraph_x                          , netgraph_y, graphwidth, graphheight, graphscale, "incoming", textsize, c->incoming_packetcounter, c->incoming_netgraph);
+       SCR_DrawNetGraph_DrawGraph(netgraph_x + graphwidth + separator1, netgraph_y, graphwidth, graphheight, graphscale, "outgoing", textsize, c->outgoing_packetcounter, c->outgoing_netgraph);
        index++;
 
        if (sv.active && shownetgraph.integer >= 2)
        {
                for (i = 0;i < svs.maxclients;i++)
                {
-                       if (!svs.clients[i].netconnection)
+                       c = svs.clients[i].netconnection;
+                       if (!c)
                                continue;
-                       netgraph_x = (vid_conwidth.integer + separator2) - (1 + (index % netgraphsperrow)) * (barwidth * NETGRAPH_PACKETS * 2 + separator1 + separator2);
-                       netgraph_y = (vid_conheight.integer - 48 + separator2) - (1 + (index / netgraphsperrow)) * (barheight + textsize + separator2);
-                       SCR_DrawNetGraph_DrawConnection_Server(svs.clients[i].netconnection, netgraph_x, netgraph_y, barwidth, barheight, bardivide, va("%s", svs.clients[i].name), separator1, "", textsize);
+                       netgraph_x = (vid_conwidth.integer + separator2) - (1 + (index % netgraphsperrow)) * (graphwidth * 2 + separator1 + separator2);
+                       netgraph_y = (vid_conheight.integer - 48 + separator2) - (1 + (index / netgraphsperrow)) * (graphheight + textsize + separator2);
+                       SCR_DrawNetGraph_DrawGraph(netgraph_x                          , netgraph_y, graphwidth, graphheight, graphscale, va("%s", svs.clients[i].name), textsize, c->outgoing_packetcounter, c->outgoing_netgraph);
+                       SCR_DrawNetGraph_DrawGraph(netgraph_x + graphwidth + separator1, netgraph_y, graphwidth, graphheight, graphscale, ""                           , textsize, c->incoming_packetcounter, c->incoming_netgraph);
                        index++;
                }
        }
index 7947ccfc19e7cbe2ae60dc764a7164e1a7c37821..dc84be9d5411153c8c944ac5d0884f76e6387b90 100644 (file)
@@ -139,7 +139,7 @@ void Host_Status_f (void)
                        packetloss = 0;
                        if (client->netconnection)
                                for (j = 0;j < NETGRAPH_PACKETS;j++)
-                                       if (client->netconnection->incoming_unreliablesize[j] == NETGRAPH_LOSTPACKET)
+                                       if (client->netconnection->incoming_netgraph[j].unreliablebytes == NETGRAPH_LOSTPACKET)
                                                packetloss++;
                        packetloss = packetloss * 100 / NETGRAPH_PACKETS;
                        ping = bound(0, (int)floor(client->ping*1000+0.5), 9999);
@@ -2715,7 +2715,7 @@ void Host_Pings_f (void)
                packetloss = 0;
                if (svs.clients[i].netconnection)
                        for (j = 0;j < NETGRAPH_PACKETS;j++)
-                               if (svs.clients[i].netconnection->incoming_unreliablesize[j] == NETGRAPH_LOSTPACKET)
+                               if (svs.clients[i].netconnection->incoming_netgraph[j].unreliablebytes == NETGRAPH_LOSTPACKET)
                                        packetloss++;
                packetloss = packetloss * 100 / NETGRAPH_PACKETS;
                ping = (int)floor(svs.clients[i].ping*1000+0.5);
index b079a370d3fb2a941b0b717459cd0ac0ab5022fd..ea6e92c0b90595eafbc5216d044029a24f7bebb9 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -603,14 +603,15 @@ int NetConn_WriteString(lhnetsocket_t *mysocket, const char *string, const lhnet
 qboolean NetConn_CanSend(netconn_t *conn)
 {
        conn->outgoing_packetcounter = (conn->outgoing_packetcounter + 1) % NETGRAPH_PACKETS;
-       conn->outgoing_unreliablesize[conn->outgoing_packetcounter] = NETGRAPH_NOPACKET;
-       conn->outgoing_reliablesize[conn->outgoing_packetcounter] = NETGRAPH_NOPACKET;
-       conn->outgoing_acksize[conn->outgoing_packetcounter] = NETGRAPH_NOPACKET;
+       conn->outgoing_netgraph[conn->outgoing_packetcounter].time            = realtime;
+       conn->outgoing_netgraph[conn->outgoing_packetcounter].unreliablebytes = NETGRAPH_NOPACKET;
+       conn->outgoing_netgraph[conn->outgoing_packetcounter].reliablebytes   = NETGRAPH_NOPACKET;
+       conn->outgoing_netgraph[conn->outgoing_packetcounter].ackbytes        = NETGRAPH_NOPACKET;
        if (realtime > conn->cleartime)
                return true;
        else
        {
-               conn->outgoing_unreliablesize[conn->outgoing_packetcounter] = NETGRAPH_CHOKEDPACKET;
+               conn->outgoing_netgraph[conn->outgoing_packetcounter].unreliablebytes = NETGRAPH_CHOKEDPACKET;
                return false;
        }
 }
@@ -622,8 +623,8 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers
        // if this packet was supposedly choked, but we find ourselves sending one
        // anyway, make sure the size counting starts at zero
        // (this mostly happens on level changes and disconnects and such)
-       if (conn->outgoing_unreliablesize[conn->outgoing_packetcounter] == NETGRAPH_CHOKEDPACKET)
-               conn->outgoing_unreliablesize[conn->outgoing_packetcounter] = NETGRAPH_NOPACKET;
+       if (conn->outgoing_netgraph[conn->outgoing_packetcounter].unreliablebytes == NETGRAPH_CHOKEDPACKET)
+               conn->outgoing_netgraph[conn->outgoing_packetcounter].unreliablebytes = NETGRAPH_NOPACKET;
 
        if (protocol == PROTOCOL_QUAKEWORLD)
        {
@@ -666,12 +667,12 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers
                        return -1;
                }
 
-               conn->outgoing_unreliablesize[conn->outgoing_packetcounter] += packetLen;
+               conn->outgoing_netgraph[conn->outgoing_packetcounter].unreliablebytes += packetLen + 28;
 
                // add the reliable message if there is one
                if (sendreliable)
                {
-                       conn->outgoing_reliablesize[conn->outgoing_packetcounter] += conn->sendMessageLength;
+                       conn->outgoing_netgraph[conn->outgoing_packetcounter].reliablebytes += conn->sendMessageLength + 28;
                        memcpy(sendbuffer + packetLen, conn->sendMessage, conn->sendMessageLength);
                        packetLen += conn->sendMessageLength;
                        conn->qw.last_reliable_sequence = conn->outgoing_unreliable_sequence;
@@ -680,7 +681,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers
                // add the unreliable message if possible
                if (packetLen + data->cursize <= 1400)
                {
-                       conn->outgoing_unreliablesize[conn->outgoing_packetcounter] += data->cursize;
+                       conn->outgoing_netgraph[conn->outgoing_packetcounter].unreliablebytes += data->cursize + 28;
                        memcpy(sendbuffer + packetLen, data->data, data->cursize);
                        packetLen += data->cursize;
                }
@@ -720,7 +721,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers
                        header[1] = BigLong(conn->nq.sendSequence - 1);
                        memcpy(sendbuffer + NET_HEADERSIZE, conn->sendMessage, dataLen);
 
-                       conn->outgoing_reliablesize[conn->outgoing_packetcounter] += packetLen;
+                       conn->outgoing_netgraph[conn->outgoing_packetcounter].reliablebytes += packetLen + 28;
 
                        if (NetConn_Write(conn->mysocket, (void *)&sendbuffer, packetLen, &conn->peeraddress) == (int)packetLen)
                        {
@@ -771,7 +772,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers
 
                        conn->nq.sendSequence++;
 
-                       conn->outgoing_reliablesize[conn->outgoing_packetcounter] += packetLen;
+                       conn->outgoing_netgraph[conn->outgoing_packetcounter].reliablebytes += packetLen + 28;
 
                        NetConn_Write(conn->mysocket, (void *)&sendbuffer, packetLen, &conn->peeraddress);
 
@@ -800,7 +801,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers
 
                        conn->outgoing_unreliable_sequence++;
 
-                       conn->outgoing_unreliablesize[conn->outgoing_packetcounter] += packetLen;
+                       conn->outgoing_netgraph[conn->outgoing_packetcounter].unreliablebytes += packetLen + 28;
 
                        NetConn_Write(conn->mysocket, (void *)&sendbuffer, packetLen, &conn->peeraddress);
 
@@ -1093,15 +1094,17 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len
                        while (count--)
                        {
                                conn->incoming_packetcounter = (conn->incoming_packetcounter + 1) % NETGRAPH_PACKETS;
-                               conn->incoming_unreliablesize[conn->incoming_packetcounter] = NETGRAPH_LOSTPACKET;
-                               conn->incoming_reliablesize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET;
-                               conn->incoming_acksize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET;
+                               conn->incoming_netgraph[conn->incoming_packetcounter].time            = realtime;
+                               conn->incoming_netgraph[conn->incoming_packetcounter].unreliablebytes = NETGRAPH_LOSTPACKET;
+                               conn->incoming_netgraph[conn->incoming_packetcounter].reliablebytes   = NETGRAPH_NOPACKET;
+                               conn->incoming_netgraph[conn->incoming_packetcounter].ackbytes        = NETGRAPH_NOPACKET;
                        }
                }
                conn->incoming_packetcounter = (conn->incoming_packetcounter + 1) % NETGRAPH_PACKETS;
-               conn->incoming_unreliablesize[conn->incoming_packetcounter] = originallength;
-               conn->incoming_reliablesize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET;
-               conn->incoming_acksize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET;
+               conn->incoming_netgraph[conn->incoming_packetcounter].time            = realtime;
+               conn->incoming_netgraph[conn->incoming_packetcounter].unreliablebytes = originallength + 28;
+               conn->incoming_netgraph[conn->incoming_packetcounter].reliablebytes   = NETGRAPH_NOPACKET;
+               conn->incoming_netgraph[conn->incoming_packetcounter].ackbytes        = NETGRAPH_NOPACKET;
                if (reliable_ack == conn->qw.reliable_sequence)
                {
                        // received, now we will be able to send another reliable message
@@ -1152,15 +1155,17 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len
                                                while (count--)
                                                {
                                                        conn->incoming_packetcounter = (conn->incoming_packetcounter + 1) % NETGRAPH_PACKETS;
-                                                       conn->incoming_unreliablesize[conn->incoming_packetcounter] = NETGRAPH_LOSTPACKET;
-                                                       conn->incoming_reliablesize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET;
-                                                       conn->incoming_acksize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET;
+                                                       conn->incoming_netgraph[conn->incoming_packetcounter].time            = realtime;
+                                                       conn->incoming_netgraph[conn->incoming_packetcounter].unreliablebytes = NETGRAPH_LOSTPACKET;
+                                                       conn->incoming_netgraph[conn->incoming_packetcounter].reliablebytes   = NETGRAPH_NOPACKET;
+                                                       conn->incoming_netgraph[conn->incoming_packetcounter].ackbytes        = NETGRAPH_NOPACKET;
                                                }
                                        }
                                        conn->incoming_packetcounter = (conn->incoming_packetcounter + 1) % NETGRAPH_PACKETS;
-                                       conn->incoming_unreliablesize[conn->incoming_packetcounter] = originallength;
-                                       conn->incoming_reliablesize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET;
-                                       conn->incoming_acksize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET;
+                                       conn->incoming_netgraph[conn->incoming_packetcounter].time            = realtime;
+                                       conn->incoming_netgraph[conn->incoming_packetcounter].unreliablebytes = originallength + 28;
+                                       conn->incoming_netgraph[conn->incoming_packetcounter].reliablebytes   = NETGRAPH_NOPACKET;
+                                       conn->incoming_netgraph[conn->incoming_packetcounter].ackbytes        = NETGRAPH_NOPACKET;
                                        conn->nq.unreliableReceiveSequence = sequence + 1;
                                        conn->lastMessageTime = realtime;
                                        conn->timeout = realtime + newtimeout;
@@ -1179,7 +1184,7 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len
                        }
                        else if (flags & NETFLAG_ACK)
                        {
-                               conn->incoming_acksize[conn->incoming_packetcounter] += originallength;
+                               conn->incoming_netgraph[conn->incoming_packetcounter].ackbytes += originallength + 28;
                                if (sequence == (conn->nq.sendSequence - 1))
                                {
                                        if (sequence == conn->nq.ackSequence)
@@ -1238,8 +1243,8 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len
                        else if (flags & NETFLAG_DATA)
                        {
                                unsigned int temppacket[2];
-                               conn->incoming_reliablesize[conn->incoming_packetcounter] += originallength;
-                               conn->outgoing_acksize[conn->outgoing_packetcounter] += 8;
+                               conn->incoming_netgraph[conn->incoming_packetcounter].reliablebytes   += originallength + 28;
+                               conn->outgoing_netgraph[conn->outgoing_packetcounter].ackbytes        += 8 + 28;
                                temppacket[0] = BigLong(8 | NETFLAG_ACK);
                                temppacket[1] = BigLong(sequence);
                                NetConn_Write(conn->mysocket, (unsigned char *)temppacket, 8, &conn->peeraddress);
index f8b42fa9fae7d544999325db7281d25d835e78c2..f7159d6a8ab073c4db857aef5d41c27fa774abb9 100755 (executable)
--- a/netconn.h
+++ b/netconn.h
@@ -121,6 +121,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define CCREP_RULE_INFO                0x85
 #define CCREP_RCON             0x86 // RocketGuy: ProQuake rcon support
 
+typedef struct netgraphitem_s
+{
+       double time;
+       int reliablebytes;
+       int unreliablebytes;
+       int ackbytes;
+}
+netgraphitem_t;
+
 typedef struct netconn_s
 {
        struct netconn_s *next;
@@ -200,18 +209,14 @@ typedef struct netconn_s
 
        // this tracks packet loss and packet sizes on the most recent packets
        // used by shownetgraph feature
-#define NETGRAPH_PACKETS 100
+#define NETGRAPH_PACKETS 256
 #define NETGRAPH_NOPACKET 0
 #define NETGRAPH_LOSTPACKET -1
 #define NETGRAPH_CHOKEDPACKET -2
        int incoming_packetcounter;
-       int incoming_reliablesize[NETGRAPH_PACKETS];
-       int incoming_unreliablesize[NETGRAPH_PACKETS];
-       int incoming_acksize[NETGRAPH_PACKETS];
+       netgraphitem_t incoming_netgraph[NETGRAPH_PACKETS];
        int outgoing_packetcounter;
-       int outgoing_reliablesize[NETGRAPH_PACKETS];
-       int outgoing_unreliablesize[NETGRAPH_PACKETS];
-       int outgoing_acksize[NETGRAPH_PACKETS];
+       netgraphitem_t outgoing_netgraph[NETGRAPH_PACKETS];
 
        char address[128];
 } netconn_t;