2001-05-22 06:00:38 +00:00
|
|
|
/*
|
|
|
|
cl_ngraph.c
|
|
|
|
|
|
|
|
client network diagnostic graph
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-06-19 22:05:13 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-05-22 06:00:38 +00:00
|
|
|
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-05-22 06:00:38 +00:00
|
|
|
#include "QF/draw.h"
|
|
|
|
#include "QF/render.h"
|
2001-12-09 14:05:30 +00:00
|
|
|
#include "QF/screen.h"
|
2021-07-10 09:04:34 +00:00
|
|
|
#include "QF/va.h"
|
2023-01-20 18:34:33 +00:00
|
|
|
#include "QF/ui/canvas.h"
|
2021-07-10 09:04:34 +00:00
|
|
|
#include "QF/ui/view.h"
|
2001-05-22 06:00:38 +00:00
|
|
|
|
2022-11-02 01:33:06 +00:00
|
|
|
#include "client/hud.h"
|
2022-11-02 06:08:09 +00:00
|
|
|
#include "client/screen.h"
|
2022-11-02 01:33:06 +00:00
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
#include "compat.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
|
|
|
|
#include "qw/include/cl_parse.h"
|
|
|
|
#include "qw/include/client.h"
|
2022-12-01 04:11:16 +00:00
|
|
|
#include "client/sbar.h"
|
2001-05-22 06:00:38 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
int cl_netgraph;
|
|
|
|
static cvar_t cl_netgraph_cvar = {
|
|
|
|
.name = "cl_netgraph",
|
|
|
|
.description =
|
|
|
|
"Toggle the display of a graph showing network performance",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &cl_netgraph },
|
|
|
|
};
|
|
|
|
float cl_netgraph_alpha;
|
|
|
|
static cvar_t cl_netgraph_alpha_cvar = {
|
|
|
|
.name = "cl_netgraph_alpha",
|
|
|
|
.description =
|
|
|
|
"Net graph translucency",
|
|
|
|
.default_value = "0.5",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &cl_netgraph_alpha },
|
|
|
|
};
|
|
|
|
int cl_netgraph_box;
|
|
|
|
static cvar_t cl_netgraph_box_cvar = {
|
|
|
|
.name = "cl_netgraph_box",
|
|
|
|
.description =
|
|
|
|
" Draw box around net graph",
|
|
|
|
.default_value = "1",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &cl_netgraph_box },
|
|
|
|
};
|
|
|
|
int cl_netgraph_height;
|
|
|
|
static cvar_t cl_netgraph_height_cvar = {
|
|
|
|
.name = "cl_netgraph_height",
|
|
|
|
.description =
|
|
|
|
"Set the fullscale (1s) height of the graph",
|
|
|
|
.default_value = "32",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &cl_netgraph_height },
|
|
|
|
};
|
2022-11-02 01:33:06 +00:00
|
|
|
|
|
|
|
static view_t cl_netgraph_view;
|
2021-07-11 01:59:27 +00:00
|
|
|
|
|
|
|
static void
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
cl_netgraph_f (void *data, const cvar_t *cvar)
|
2021-07-11 01:59:27 +00:00
|
|
|
{
|
2022-10-31 15:40:52 +00:00
|
|
|
if (View_Valid (cl_netgraph_view)) {
|
|
|
|
View_SetVisible (cl_netgraph_view, cl_netgraph != 0);
|
2021-07-11 01:59:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
cl_netgraph_height_f (void *data, const cvar_t *cvar)
|
2021-07-11 01:59:27 +00:00
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
cl_netgraph_height = max (32, cl_netgraph_height);
|
2022-10-31 15:40:52 +00:00
|
|
|
if (View_Valid (cl_netgraph_view)) {
|
|
|
|
view_pos_t len = View_GetLen (cl_netgraph_view);
|
|
|
|
View_SetLen (cl_netgraph_view, len.x, cl_netgraph_height + 25);
|
|
|
|
View_UpdateHierarchy (cl_netgraph_view);
|
2021-07-11 01:59:27 +00:00
|
|
|
}
|
|
|
|
}
|
2001-08-28 23:05:45 +00:00
|
|
|
|
2022-11-02 01:33:06 +00:00
|
|
|
static void
|
|
|
|
CL_NetGraph (view_pos_t abs, view_pos_t len)
|
2001-05-22 06:00:38 +00:00
|
|
|
{
|
2021-07-11 01:59:27 +00:00
|
|
|
int lost, a, l, x, y, i, o;
|
|
|
|
int timings[NET_TIMINGS];
|
2001-05-22 06:00:38 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (cl_netgraph_box) {
|
2022-10-31 15:40:52 +00:00
|
|
|
r_funcs->Draw_TextBox (abs.x, abs.y, NET_TIMINGS / 8,
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
cl_netgraph_height / 8 + 1,
|
|
|
|
cl_netgraph_alpha * 255);
|
2021-07-11 01:59:27 +00:00
|
|
|
}
|
2001-05-22 06:00:38 +00:00
|
|
|
|
|
|
|
lost = CL_CalcNet ();
|
2022-10-31 15:40:52 +00:00
|
|
|
x = abs.x + 8;
|
|
|
|
y = abs.y + len.y - 9;
|
2001-05-22 06:00:38 +00:00
|
|
|
|
|
|
|
l = NET_TIMINGS;
|
2022-10-31 15:40:52 +00:00
|
|
|
if (l > len.x - 8)
|
|
|
|
l = len.x - 8;
|
2002-07-03 05:40:33 +00:00
|
|
|
i = cls.netchan.outgoing_sequence & NET_TIMINGSMASK;
|
2001-05-22 06:00:38 +00:00
|
|
|
a = i - l;
|
2021-07-11 01:59:27 +00:00
|
|
|
o = 0;
|
2001-05-22 06:00:38 +00:00
|
|
|
if (a < 0) {
|
2021-07-11 01:59:27 +00:00
|
|
|
memcpy (timings + o, packet_latency + a + NET_TIMINGS,
|
|
|
|
-a * sizeof (timings[0]));
|
|
|
|
o -= a;
|
2001-05-22 06:00:38 +00:00
|
|
|
l += a;
|
|
|
|
a = 0;
|
|
|
|
}
|
2021-07-11 01:59:27 +00:00
|
|
|
memcpy (timings + o, packet_latency + a, l * sizeof (timings[0]));
|
|
|
|
r_funcs->R_LineGraph (x, y, timings,
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
NET_TIMINGS, cl_netgraph_height);
|
2001-05-22 06:00:38 +00:00
|
|
|
|
2022-10-31 15:40:52 +00:00
|
|
|
x = abs.x + 8;
|
|
|
|
y = abs.y + 8;
|
2021-07-10 09:04:34 +00:00
|
|
|
r_funcs->Draw_String (x, y, va (0, "%3i%% packet loss", lost));
|
2022-10-31 15:40:52 +00:00
|
|
|
/*
|
|
|
|
//FIXME don't do every frame
|
|
|
|
view_move (cl_netgraph_view, cl_netgraph_view->xpos, hud_sb_lines);
|
|
|
|
view_setgravity (cl_netgraph_view,
|
|
|
|
hud_swap ? grav_southeast : grav_southwest);
|
|
|
|
*/
|
2001-05-22 06:00:38 +00:00
|
|
|
}
|
2021-07-11 01:59:27 +00:00
|
|
|
|
2022-11-02 01:33:06 +00:00
|
|
|
void
|
|
|
|
CL_NetGraph_Init (void)
|
|
|
|
{
|
2023-01-20 18:34:33 +00:00
|
|
|
ecs_system_t vsys = {
|
|
|
|
.reg = cl_canvas_sys.reg,
|
|
|
|
.base = cl_canvas_sys.view_base,
|
|
|
|
};
|
|
|
|
cl_netgraph_view = View_New (vsys, cl_screen_view);
|
2022-11-10 12:23:04 +00:00
|
|
|
View_SetPos (cl_netgraph_view, 0, 64);
|
2022-11-02 01:33:06 +00:00
|
|
|
View_SetLen (cl_netgraph_view, NET_TIMINGS + 16, cl_netgraph_height + 25);
|
|
|
|
View_SetGravity (cl_netgraph_view, grav_southwest);
|
|
|
|
void *f = CL_NetGraph;
|
2023-01-20 18:34:33 +00:00
|
|
|
Ent_SetComponent (cl_netgraph_view.id, canvas_func,
|
|
|
|
cl_netgraph_view.reg, &f);
|
2022-11-02 01:33:06 +00:00
|
|
|
View_SetVisible (cl_netgraph_view, cl_netgraph);
|
|
|
|
}
|
|
|
|
|
2021-07-11 01:59:27 +00:00
|
|
|
void
|
|
|
|
CL_NetGraph_Init_Cvars (void)
|
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&cl_netgraph_cvar, cl_netgraph_f, 0);
|
|
|
|
Cvar_Register (&cl_netgraph_alpha_cvar, 0, 0);
|
|
|
|
Cvar_Register (&cl_netgraph_box_cvar, 0, 0);
|
|
|
|
Cvar_Register (&cl_netgraph_height_cvar, cl_netgraph_height_f, 0);
|
2021-07-11 01:59:27 +00:00
|
|
|
}
|
2022-11-10 06:14:29 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
CL_NetUpdate (void)
|
|
|
|
{
|
|
|
|
if ((hud_ping || sbar_showscores)
|
|
|
|
&& realtime - cl.last_ping_request > 2) {
|
|
|
|
// FIXME this should be on a timer
|
|
|
|
cl.last_ping_request = realtime;
|
|
|
|
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
|
|
|
|
SZ_Print (&cls.netchan.message, "pings");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hud_pl) {
|
|
|
|
Sbar_UpdatePL (CL_CalcNet ());
|
|
|
|
}
|
|
|
|
}
|