Browse Source

engine: client: move netgraph cvars to static allocation

pull/2/head
Alibek Omarov 2 years ago
parent
commit
03ec2f603b
  1. 64
      engine/client/cl_netgraph.c
  2. 2
      engine/client/client.h
  3. 2
      engine/client/console.c

64
engine/client/cl_netgraph.c

@ -33,12 +33,12 @@ GNU General Public License for more details.
#define NETGRAPH_NET_COLORS 5 #define NETGRAPH_NET_COLORS 5
#define NUM_LATENCY_SAMPLES 8 #define NUM_LATENCY_SAMPLES 8
convar_t *net_graph; CVAR_DEFINE_AUTO( net_graph, "0", FCVAR_ARCHIVE, "draw network usage graph" );
static convar_t *net_graphpos; static CVAR_DEFINE_AUTO( net_graphpos, "1", FCVAR_ARCHIVE, "network usage graph position" );
static convar_t *net_graphwidth; static CVAR_DEFINE_AUTO( net_scale, "5", FCVAR_ARCHIVE, "network usage graph scale level" );
static convar_t *net_graphheight; static CVAR_DEFINE_AUTO( net_graphwidth, "192", FCVAR_ARCHIVE, "network usage graph width" );
static convar_t *net_graphsolid; static CVAR_DEFINE_AUTO( net_graphheight, "64", FCVAR_ARCHIVE, "network usage graph height" );
static convar_t *net_scale; static CVAR_DEFINE_AUTO( net_graphsolid, "1", FCVAR_ARCHIVE, "fill segments in network usage graph" );
static struct packet_latency_t static struct packet_latency_t
{ {
@ -211,7 +211,7 @@ static void NetGraph_GetFrameData( float *latency, int *latency_count )
else else
{ {
int frame_latency = Q_min( 1.0f, f->latency ); int frame_latency = Q_min( 1.0f, f->latency );
p->latency = (( frame_latency + 0.1f ) / 1.1f ) * ( net_graphheight->value - NETGRAPH_LERP_HEIGHT - 2 ); p->latency = (( frame_latency + 0.1f ) / 1.1f ) * ( net_graphheight.value - NETGRAPH_LERP_HEIGHT - 2 );
if( i > cls.netchan.incoming_sequence - NUM_LATENCY_SAMPLES ) if( i > cls.netchan.incoming_sequence - NUM_LATENCY_SAMPLES )
{ {
@ -260,7 +260,7 @@ static void NetGraph_DrawTimes( wrect_t rect, int x, int w )
for( a = 0; a < w; a++ ) for( a = 0; a < w; a++ )
{ {
i = ( cls.netchan.outgoing_sequence - a ) & NET_TIMINGS_MASK; i = ( cls.netchan.outgoing_sequence - a ) & NET_TIMINGS_MASK;
h = Q_min(( netstat_cmdinfo[i].cmd_lerp / 3.0f ) * NETGRAPH_LERP_HEIGHT, net_graphheight->value * 0.7f); h = Q_min(( netstat_cmdinfo[i].cmd_lerp / 3.0f ) * NETGRAPH_LERP_HEIGHT, net_graphheight.value * 0.7f);
fill.left = x + w - a - 1; fill.left = x + w - a - 1;
fill.right = fill.bottom = 1; fill.right = fill.bottom = 1;
@ -273,7 +273,7 @@ static void NetGraph_DrawTimes( wrect_t rect, int x, int w )
h -= extrap_point; h -= extrap_point;
fill.top -= extrap_point; fill.top -= extrap_point;
if( !net_graphsolid->value ) if( !net_graphsolid.value )
{ {
fill.top -= (h - 1); fill.top -= (h - 1);
start = (h - 1); start = (h - 1);
@ -295,7 +295,7 @@ static void NetGraph_DrawTimes( wrect_t rect, int x, int w )
fill.top -= h; fill.top -= h;
h = extrap_point - h; h = extrap_point - h;
if( !net_graphsolid->value ) if( !net_graphsolid.value )
h = 1; h = 1;
for( j = 0; j < h; j++ ) for( j = 0; j < h; j++ )
@ -334,7 +334,7 @@ NetGraph_DrawHatches
*/ */
static void NetGraph_DrawHatches( int x, int y ) static void NetGraph_DrawHatches( int x, int y )
{ {
int ystep = (int)( 10.0f / net_scale->value ); int ystep = (int)( 10.0f / net_scale.value );
byte colorminor[4] = { 0, 63, 63, 200 }; byte colorminor[4] = { 0, 63, 63, 200 };
byte color[4] = { 0, 200, 0, 255 }; byte color[4] = { 0, 200, 0, 255 };
wrect_t hatch = { x, 4, y, 1 }; wrect_t hatch = { x, 4, y, 1 };
@ -342,9 +342,9 @@ static void NetGraph_DrawHatches( int x, int y )
ystep = Q_max( ystep, 1 ); ystep = Q_max( ystep, 1 );
for( starty = hatch.top; hatch.top > 0 && ((starty - hatch.top) * net_scale->value < (maxmsgbytes + 50)); hatch.top -= ystep ) for( starty = hatch.top; hatch.top > 0 && ((starty - hatch.top) * net_scale.value < (maxmsgbytes + 50)); hatch.top -= ystep )
{ {
if(!((int)((starty - hatch.top) * net_scale->value ) % 50 )) if(!((int)((starty - hatch.top) * net_scale.value ) % 50 ))
{ {
NetGraph_DrawRect( &hatch, color ); NetGraph_DrawRect( &hatch, color );
} }
@ -370,7 +370,7 @@ static void NetGraph_DrawTextFields( int x, int y, int w, wrect_t rect, int coun
int pty = Q_max( rect.top + rect.bottom - NETGRAPH_LERP_HEIGHT - 3, 1 ); int pty = Q_max( rect.top + rect.bottom - NETGRAPH_LERP_HEIGHT - 3, 1 );
int out, i = ( cls.netchan.outgoing_sequence - 1 ) & NET_TIMINGS_MASK; int out, i = ( cls.netchan.outgoing_sequence - 1 ) & NET_TIMINGS_MASK;
int j = cls.netchan.incoming_sequence & NET_TIMINGS_MASK; int j = cls.netchan.incoming_sequence & NET_TIMINGS_MASK;
int last_y = y - net_graphheight->value; int last_y = y - net_graphheight.value;
if( count > 0 ) if( count > 0 )
{ {
@ -391,7 +391,7 @@ static void NetGraph_DrawTextFields( int x, int y, int w, wrect_t rect, int coun
if( framerate > 0.0f ) if( framerate > 0.0f )
{ {
y -= net_graphheight->value; y -= net_graphheight.value;
CL_DrawStringf( font, x, y, colors, FONT_DRAW_NORENDERMODE, "%.1f fps" , 1.0f / framerate); CL_DrawStringf( font, x, y, colors, FONT_DRAW_NORENDERMODE, "%.1f fps" , 1.0f / framerate);
@ -435,12 +435,12 @@ NetGraph_DrawDataSegment
*/ */
static int NetGraph_DrawDataSegment( wrect_t *fill, int bytes, byte r, byte g, byte b, byte a ) static int NetGraph_DrawDataSegment( wrect_t *fill, int bytes, byte r, byte g, byte b, byte a )
{ {
float h = bytes / net_scale->value; float h = bytes / net_scale.value;
byte colors[4] = { r, g, b, a }; byte colors[4] = { r, g, b, a };
fill->top -= (int)h; fill->top -= (int)h;
if( net_graphsolid->value ) if( net_graphsolid.value )
fill->bottom = (int)h; fill->bottom = (int)h;
else fill->bottom = 1; else fill->bottom = 1;
@ -498,7 +498,7 @@ NetGraph_DrawDataUsage
static void NetGraph_DrawDataUsage( int x, int y, int w, int graphtype ) static void NetGraph_DrawDataUsage( int x, int y, int w, int graphtype )
{ {
int a, i, h, lastvalidh = 0, ping; int a, i, h, lastvalidh = 0, ping;
int pingheight = net_graphheight->value - NETGRAPH_LERP_HEIGHT - 2; int pingheight = net_graphheight.value - NETGRAPH_LERP_HEIGHT - 2;
wrect_t fill = { 0 }; wrect_t fill = { 0 };
byte color[4]; byte color[4];
@ -554,7 +554,7 @@ static void NetGraph_DrawDataUsage( int x, int y, int w, int graphtype )
continue; continue;
color[0] = color[1] = color[2] = color[3] = 255; color[0] = color[1] = color[2] = color[3] = 255;
fill.top = y - net_graphheight->value - 1; fill.top = y - net_graphheight.value - 1;
fill.bottom = 1; fill.bottom = 1;
if( NetGraph_AtEdge( a, w )) if( NetGraph_AtEdge( a, w ))
@ -589,7 +589,7 @@ static void NetGraph_DrawDataUsage( int x, int y, int w, int graphtype )
if( !NetGraph_DrawDataSegment( &fill, netstat_graph[i].voicebytes, 255, 255, 255, 255 )) if( !NetGraph_DrawDataSegment( &fill, netstat_graph[i].voicebytes, 255, 255, 255, 255 ))
continue; continue;
fill.top = y - net_graphheight->value - 1; fill.top = y - net_graphheight.value - 1;
fill.bottom = 1; fill.bottom = 1;
fill.top -= 2; fill.top -= 2;
@ -598,7 +598,7 @@ static void NetGraph_DrawDataUsage( int x, int y, int w, int graphtype )
} }
if( graphtype >= 2 ) if( graphtype >= 2 )
NetGraph_DrawHatches( x, y - net_graphheight->value - 1 ); NetGraph_DrawHatches( x, y - net_graphheight.value - 1 );
} }
/* /*
@ -613,12 +613,12 @@ static void NetGraph_GetScreenPos( wrect_t *rect, int *w, int *x, int *y )
rect->right = refState.width; rect->right = refState.width;
rect->bottom = refState.height; rect->bottom = refState.height;
*w = Q_min( NET_TIMINGS, net_graphwidth->value ); *w = Q_min( NET_TIMINGS, net_graphwidth.value );
if( rect->right < *w + 10 ) if( rect->right < *w + 10 )
*w = rect->right - 10; *w = rect->right - 10;
// detect x and y position // detect x and y position
switch( (int)net_graphpos->value ) switch( (int)net_graphpos.value )
{ {
case 1: // right sided case 1: // right sided
*x = rect->left + rect->right - 5 - *w; *x = rect->left + rect->right - 5 - *w;
@ -661,16 +661,16 @@ void SCR_DrawNetGraph( void )
{ {
graphtype = 2; graphtype = 2;
} }
else if( net_graph->value != 0.0f ) else if( net_graph.value != 0.0f )
{ {
graphtype = (int)net_graph->value; graphtype = (int)net_graph.value;
} }
else else
{ {
return; return;
} }
if( net_scale->value <= 0 ) if( net_scale.value <= 0 )
Cvar_SetValue( "net_scale", 0.1f ); Cvar_SetValue( "net_scale", 0.1f );
NetGraph_GetScreenPos( &rect, &w, &x, &y ); NetGraph_GetScreenPos( &rect, &w, &x, &y );
@ -697,12 +697,12 @@ void SCR_DrawNetGraph( void )
void CL_InitNetgraph( void ) void CL_InitNetgraph( void )
{ {
net_graph = Cvar_Get( "net_graph", "0", FCVAR_ARCHIVE, "draw network usage graph" ); Cvar_RegisterVariable( &net_graph );
net_graphpos = Cvar_Get( "net_graphpos", "1", FCVAR_ARCHIVE, "network usage graph position" ); Cvar_RegisterVariable( &net_graphpos );
net_scale = Cvar_Get( "net_scale", "5", FCVAR_ARCHIVE, "network usage graph scale level" ); Cvar_RegisterVariable( &net_scale );
net_graphwidth = Cvar_Get( "net_graphwidth", "192", FCVAR_ARCHIVE, "network usage graph width" ); Cvar_RegisterVariable( &net_graphwidth );
net_graphheight = Cvar_Get( "net_graphheight", "64", FCVAR_ARCHIVE, "network usage graph height" ); Cvar_RegisterVariable( &net_graphheight );
net_graphsolid = Cvar_Get( "net_graphsolid", "1", FCVAR_ARCHIVE, "fill segments in network usage graph" ); Cvar_RegisterVariable( &net_graphsolid );
packet_loss = packet_choke = 0.0; packet_loss = packet_choke = 0.0;
NetGraph_InitColors(); NetGraph_InitColors();

2
engine/client/client.h

@ -694,7 +694,7 @@ extern convar_t scr_centertime;
extern convar_t scr_viewsize; extern convar_t scr_viewsize;
extern convar_t scr_loading; extern convar_t scr_loading;
extern convar_t v_dark; // start from dark extern convar_t v_dark; // start from dark
extern convar_t *net_graph; extern convar_t net_graph;
extern convar_t rate; extern convar_t rate;
extern convar_t m_ignore; extern convar_t m_ignore;
extern convar_t r_showtree; extern convar_t r_showtree;

2
engine/client/console.c

@ -2059,7 +2059,7 @@ void Con_DrawVersion( void )
if( host.force_draw_version_time > host.realtime ) if( host.force_draw_version_time > host.realtime )
draw_version = true; draw_version = true;
if(( cls.key_dest != key_menu && !draw_version ) || CL_IsDevOverviewMode() == 2 || net_graph->value ) if(( cls.key_dest != key_menu && !draw_version ) || CL_IsDevOverviewMode() == 2 || net_graph.value )
return; return;
if( draw_version ) if( draw_version )

Loading…
Cancel
Save