2004-08-22 22:29:09 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
// gl_ngraph.c
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
2011-10-27 16:16:29 +00:00
|
|
|
#include "shader.h"
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
extern qbyte *draw_chars; // 8*8 graphic characters
|
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
static texid_t netgraphtexture; // netgraph texture
|
|
|
|
static shader_t *netgraphshader;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2014-04-13 04:23:13 +00:00
|
|
|
static int timehistory[NET_TIMINGS];
|
|
|
|
static int findex;
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
#define NET_GRAPHHEIGHT 32
|
|
|
|
|
|
|
|
static qbyte ngraph_texels[NET_GRAPHHEIGHT][NET_TIMINGS];
|
|
|
|
|
|
|
|
static void R_LineGraph (int x, int h)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int s;
|
|
|
|
int color;
|
|
|
|
|
|
|
|
s = NET_GRAPHHEIGHT;
|
|
|
|
|
|
|
|
if (h == 10000)
|
|
|
|
color = 0x6f; // yellow
|
|
|
|
else if (h == 9999)
|
|
|
|
color = 0x4f; // red
|
|
|
|
else if (h == 9998)
|
|
|
|
color = 0xd0; // blue
|
|
|
|
else
|
|
|
|
color = 0xfe; // white
|
|
|
|
|
|
|
|
if (h>s)
|
|
|
|
h = s;
|
|
|
|
|
|
|
|
for (i=0 ; i<h ; i++)
|
|
|
|
if (i & 1)
|
|
|
|
ngraph_texels[NET_GRAPHHEIGHT - i - 1][x] = 0xff;
|
|
|
|
else
|
|
|
|
ngraph_texels[NET_GRAPHHEIGHT - i - 1][x] = (qbyte)color;
|
|
|
|
|
|
|
|
for ( ; i<s ; i++)
|
|
|
|
ngraph_texels[NET_GRAPHHEIGHT - i - 1][x] = (qbyte)0xff;
|
|
|
|
}
|
|
|
|
|
2012-04-24 07:59:11 +00:00
|
|
|
/*
|
2011-10-27 16:16:29 +00:00
|
|
|
static void Draw_CharToNetGraph (int x, int y, int num)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
int row, col;
|
|
|
|
qbyte *source;
|
|
|
|
int drawline;
|
|
|
|
int nx;
|
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
if (!draw_chars)
|
|
|
|
return;
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
row = num>>4;
|
|
|
|
col = num&15;
|
|
|
|
source = draw_chars + (row<<10) + (col<<3);
|
|
|
|
|
|
|
|
for (drawline = 8; drawline; drawline--, y++)
|
|
|
|
{
|
|
|
|
for (nx=0 ; nx<8 ; nx++)
|
|
|
|
if (source[nx] != 255)
|
|
|
|
ngraph_texels[y][nx+x] = 0x60 + source[nx];
|
|
|
|
source += 128;
|
|
|
|
}
|
|
|
|
}
|
2012-04-24 07:59:11 +00:00
|
|
|
*/
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
R_NetGraph
|
|
|
|
==============
|
|
|
|
*/
|
2012-08-04 11:28:39 +00:00
|
|
|
void R_NetGraph (void)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
int a, x, i, y;
|
|
|
|
int lost;
|
|
|
|
char st[80];
|
|
|
|
unsigned ngraph_pixels[NET_GRAPHHEIGHT][NET_TIMINGS];
|
2015-04-14 23:12:17 +00:00
|
|
|
float pi, po, bi, bo;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
x = 0;
|
2014-04-13 04:23:13 +00:00
|
|
|
if (r_netgraph.value < 0)
|
|
|
|
{
|
|
|
|
lost = -1;
|
|
|
|
if (!cl.paused)
|
|
|
|
timehistory[++findex&NET_TIMINGSMASK] = (cl.currentpackentities?(cl.currentpackentities->servertime - cl.servertime)*NET_GRAPHHEIGHT*5:0);
|
|
|
|
for (a=0 ; a<NET_TIMINGS ; a++)
|
|
|
|
{
|
|
|
|
i = (findex-a) & NET_TIMINGSMASK;
|
|
|
|
R_LineGraph (NET_TIMINGS-1-a, timehistory[i]<0?10000:timehistory[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2014-04-13 04:23:13 +00:00
|
|
|
lost = CL_CalcNet(r_netgraph.value);
|
|
|
|
for (a=0 ; a<NET_TIMINGS ; a++)
|
|
|
|
{
|
|
|
|
i = (cl.movesequence-a) & NET_TIMINGSMASK;
|
|
|
|
R_LineGraph (NET_TIMINGS-1-a, packet_latency[i]);
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now load the netgraph texture into gl and draw it
|
2009-04-01 22:03:56 +00:00
|
|
|
for (y = 0; y < NET_GRAPHHEIGHT; y++)
|
|
|
|
for (x = 0; x < NET_TIMINGS; x++)
|
|
|
|
ngraph_pixels[y][x] = d_8to24rgbtable[ngraph_texels[y][x]];
|
|
|
|
|
|
|
|
x = ((vid.width - 320)>>1);
|
|
|
|
x=-x;
|
2015-04-14 23:12:17 +00:00
|
|
|
y = vid.height - sb_lines - 24 - NET_GRAPHHEIGHT - 2*8;
|
2009-04-01 22:03:56 +00:00
|
|
|
|
2015-04-14 23:12:17 +00:00
|
|
|
M_DrawTextBox (x, y, NET_TIMINGS/8, NET_GRAPHHEIGHT/8 + 3);
|
2009-04-01 22:03:56 +00:00
|
|
|
y += 8;
|
|
|
|
|
|
|
|
sprintf(st, "%3i%% packet loss", lost);
|
2009-11-04 21:16:50 +00:00
|
|
|
Draw_FunString(8, y, st);
|
2009-04-01 22:03:56 +00:00
|
|
|
y += 8;
|
2011-09-05 01:48:23 +00:00
|
|
|
|
2015-04-14 23:12:17 +00:00
|
|
|
if (NET_GetRates(cls.sockets, &pi, &po, &bi, &bo))
|
|
|
|
{
|
|
|
|
Draw_FunString(8, y+0, va("in: %g %g\n", pi, bi)); //not relevent as a limit.
|
|
|
|
Draw_FunString(8, y+8, va("out: %g %g\n", po, bo)); //not relevent as a limit.
|
|
|
|
}
|
|
|
|
y += 16;
|
|
|
|
|
2014-10-05 20:04:11 +00:00
|
|
|
Image_Upload(netgraphtexture, TF_RGBA32, ngraph_pixels, NULL, NET_TIMINGS, NET_GRAPHHEIGHT, IF_UIPIC|IF_NOMIPMAP|IF_NOPICMIP);
|
2011-10-27 16:16:29 +00:00
|
|
|
x=8;
|
|
|
|
R2D_Image(x, y, NET_TIMINGS, NET_GRAPHHEIGHT, 0, 0, 1, 1, netgraphshader);
|
2009-04-01 22:03:56 +00:00
|
|
|
}
|
|
|
|
|
2012-08-04 11:28:39 +00:00
|
|
|
void R_FrameTimeGraph (int frametime)
|
2009-04-01 22:03:56 +00:00
|
|
|
{
|
|
|
|
int a, x, i, y;
|
|
|
|
unsigned ngraph_pixels[NET_GRAPHHEIGHT][NET_TIMINGS];
|
|
|
|
|
|
|
|
timehistory[findex++&NET_TIMINGSMASK] = frametime;
|
|
|
|
|
|
|
|
x = 0;
|
|
|
|
for (a=0 ; a<NET_TIMINGS ; a++)
|
|
|
|
{
|
|
|
|
i = (findex-a) & NET_TIMINGSMASK;
|
|
|
|
R_LineGraph (NET_TIMINGS-1-a, timehistory[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// now load the netgraph texture into gl and draw it
|
2004-08-22 22:29:09 +00:00
|
|
|
for (y = 0; y < NET_GRAPHHEIGHT; y++)
|
|
|
|
for (x = 0; x < NET_TIMINGS; x++)
|
|
|
|
ngraph_pixels[y][x] = d_8to24rgbtable[ngraph_texels[y][x]];
|
|
|
|
|
|
|
|
x = ((vid.width - 320)>>1);
|
|
|
|
x=-x;
|
|
|
|
y = vid.height - sb_lines - 24 - NET_GRAPHHEIGHT - 1;
|
|
|
|
|
|
|
|
M_DrawTextBox (x, y, NET_TIMINGS/8, NET_GRAPHHEIGHT/8 + 1);
|
|
|
|
y += 8;
|
|
|
|
|
|
|
|
y += 8;
|
2011-09-05 01:48:23 +00:00
|
|
|
|
2014-10-05 20:04:11 +00:00
|
|
|
Image_Upload(netgraphtexture, TF_RGBA32, ngraph_pixels, NULL, NET_TIMINGS, NET_GRAPHHEIGHT, IF_UIPIC|IF_NOMIPMAP|IF_NOPICMIP);
|
2011-10-27 16:16:29 +00:00
|
|
|
x=8;
|
|
|
|
R2D_Image(x, y, NET_TIMINGS, NET_GRAPHHEIGHT, 0, 0, 1, 1, netgraphshader);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
void R_NetgraphInit(void)
|
|
|
|
{
|
2014-10-05 20:04:11 +00:00
|
|
|
TEXASSIGN(netgraphtexture, Image_CreateTexture("***netgraph***", NULL, IF_UIPIC|IF_NOMIPMAP));
|
2013-08-21 07:14:39 +00:00
|
|
|
netgraphshader = R_RegisterShader("netgraph", SUF_NONE,
|
2011-10-27 16:16:29 +00:00
|
|
|
"{\n"
|
2012-04-09 19:12:12 +00:00
|
|
|
"program default2d\n"
|
2011-10-27 16:16:29 +00:00
|
|
|
"{\n"
|
|
|
|
"map $diffuse\n"
|
|
|
|
"blendfunc blend\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n"
|
|
|
|
);
|
|
|
|
netgraphshader->defaulttextures.base = netgraphtexture;
|
|
|
|
}
|