diff --git a/qw/include/client.h b/qw/include/client.h index 34755d170..ac7c9885c 100644 --- a/qw/include/client.h +++ b/qw/include/client.h @@ -303,6 +303,9 @@ extern struct cvar_s *cl_name; extern struct cvar_s *cl_model_crcs; +extern struct cvar_s *show_ping; +extern struct cvar_s *show_pl; + #define MAX_STATIC_ENTITIES 128 // torches, etc diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index cf641c4c5..78409c01d 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -195,6 +195,8 @@ byte *vid_colormap; cvar_t *host_speeds; cvar_t *show_fps; +cvar_t *show_ping; +cvar_t *show_pl; cvar_t *show_time; cvar_t *cl_demospeed; @@ -1255,6 +1257,10 @@ CL_Init_Cvars (void) "sending rcon commands"); show_fps = Cvar_Get ("show_fps", "0", CVAR_NONE, NULL, "display realtime frames per second"); + show_ping = Cvar_Get ("show_ping", "o", CVAR_NONE, NULL, + "display current ping to server"); + show_pl = Cvar_Get ("show_pl", "o", CVAR_NONE, NULL, + "display current packet loss to server"); show_time = Cvar_Get ("show_time", "0", CVAR_NONE, NULL, "display the current time"); cl_predict_players2 = Cvar_Get ("cl_predict_players2", "1", CVAR_NONE, diff --git a/qw/source/cl_screen.c b/qw/source/cl_screen.c index e92e7a739..5d283cdfa 100644 --- a/qw/source/cl_screen.c +++ b/qw/source/cl_screen.c @@ -41,12 +41,15 @@ #include "QF/console.h" #include "QF/cvar.h" #include "QF/draw.h" +#include "QF/msg.h" #include "QF/pcx.h" #include "QF/screen.h" #include "QF/texture.h" +#include "QF/va.h" #include "cl_parse.h" #include "client.h" +#include "compat.h" #include "sbar.h" void @@ -61,11 +64,45 @@ SCR_DrawNet (int swap) Draw_Pic (scr_vrect.x + 64, scr_vrect.y, scr_net); } +void +CL_NetStats (int swap) +{ + int x, y; + if (!show_ping->int_val && !show_pl->int_val) + return; + x = swap ? vid.width - 104 : 0; + y = vid.height - sb_lines - 16; + // request new ping times every two second + if (realtime - cl.last_ping_request > 2) { + cl.last_ping_request = realtime; + MSG_WriteByte (&cls.netchan.message, clc_stringcmd); + SZ_Print (&cls.netchan.message, "pings"); + } + if (show_ping->int_val) { + int ping = cl.players[cl.playernum].ping; + ping = bound (0, ping, 999); + Draw_String8 (x, y, va ("%3d ms", ping)); + x+= 48; + } else if (swap) { + x += 56; + } + if (show_ping->int_val && show_pl->int_val) { + Draw_String8(x, y, "/"); + x += 8; + } + if (show_pl->int_val) { + int lost = CL_CalcNet (); + lost = bound (0, lost, 999); + Draw_String8 (x, y, va ("%3d pl", lost)); + } +} + static SCR_Func scr_funcs[] = { Draw_Crosshair, SCR_DrawRam, SCR_DrawNet, CL_NetGraph, + CL_NetStats, SCR_DrawFPS, SCR_DrawTime, SCR_DrawTurtle,