From 87f0217588e9b948c3a0cb69f72db3f94a7893ec Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 18 Nov 2024 10:29:13 +0300 Subject: [PATCH] engine: client: add cl_showcmd, yet another debugging aid to print current usercmd state --- engine/client/cl_scrn.c | 67 ++++++++++++++++++++++++++++++++++++++++- engine/client/cl_view.c | 1 + engine/client/client.h | 1 + 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index c2bd927e..ba8967e5 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -33,6 +33,7 @@ static CVAR_DEFINE_AUTO( net_speeds, "0", FCVAR_ARCHIVE, "show network packets" static CVAR_DEFINE_AUTO( cl_showfps, "0", FCVAR_ARCHIVE, "show client fps" ); static CVAR_DEFINE_AUTO( cl_showpos, "0", FCVAR_ARCHIVE, "show local player position and velocity" ); static CVAR_DEFINE_AUTO( cl_showents, "0", FCVAR_ARCHIVE | FCVAR_CHEAT, "show entities information (largely undone)" ); +static CVAR_DEFINE_AUTO( cl_showcmd, "0", 0, "visualize usercmd button presses" ); typedef struct { @@ -197,12 +198,75 @@ void SCR_DrawEnts( void ) screen[0] += 0.5f * refState.width; screen[1] += 0.5f * refState.height; - Con_DrawString( screen[0], screen[1], msg, color ); } } } +/* +============== +SCR_DrawUserCmd + +another debugging aids, shows pressed buttons +============== +*/ +void SCR_DrawUserCmd( void ) +{ + runcmd_t *pcmd = &cl.commands[( cls.netchan.outgoing_sequence - 1 ) & CL_UPDATE_MASK]; + struct + { + int mask; + const char *name; + } buttons[16] = + { + { IN_ATTACK, "attack" }, + { IN_JUMP, "jump" }, + { IN_DUCK, "duck" }, + { IN_FORWARD, "forward" }, + { IN_BACK, "back" }, + { IN_USE, "use" }, + { IN_CANCEL, "cancel" }, + { IN_LEFT, "left" }, + { IN_RIGHT, "right" }, + { IN_MOVELEFT, "moveleft" }, + { IN_MOVERIGHT, "moveright" }, + { IN_ATTACK2, "attack2" }, + { IN_RUN, "run" }, + { IN_RELOAD, "reload" }, + { IN_ALT1, "alt1" }, + { IN_SCORE, "score" }, + }; + cl_font_t *font = Con_GetCurFont(); + string msg; + int i, ypos = 100; + + if( cls.state != ca_active || !cl_showcmd.value ) + return; + + for( i = 0; i < ARRAYSIZE( buttons ); i++ ) + { + rgba_t rgba; + + rgba[0] = FBitSet( pcmd->cmd.buttons, buttons[i].mask ) ? 0 : 255; + rgba[1] = FBitSet( pcmd->cmd.buttons, buttons[i].mask ) ? 255 : 0; + rgba[2] = 0; + rgba[3] = 255; + + Con_DrawString( 100, ypos, buttons[i].name, rgba ); + + ypos += font->charHeight; + } + + Q_snprintf( msg, sizeof( msg ), + "F/S/U: %g %g %g\n" + "impulse: %u\n" + "msec: %u", + pcmd->cmd.forwardmove, pcmd->cmd.sidemove, pcmd->cmd.upmove, + pcmd->cmd.impulse, + pcmd->cmd.msec ); + Con_DrawString( 100, ypos, msg, g_color_table[7] ); +} + /* ============== SCR_NetSpeeds @@ -834,6 +898,7 @@ void SCR_Init( void ) Cvar_RegisterVariable( &net_speeds ); Cvar_RegisterVariable( &cl_showfps ); Cvar_RegisterVariable( &cl_showpos ); + Cvar_RegisterVariable( &cl_showcmd ); #ifdef _DEBUG Cvar_RegisterVariable( &cl_showents ); #endif // NDEBUG diff --git a/engine/client/cl_view.c b/engine/client/cl_view.c index bcb44978..e3b8b21d 100644 --- a/engine/client/cl_view.c +++ b/engine/client/cl_view.c @@ -534,6 +534,7 @@ void V_PostRender( void ) SCR_DrawPos(); SCR_DrawEnts(); SCR_DrawNetGraph(); + SCR_DrawUserCmd(); SV_DrawOrthoTriangles(); CL_DrawDemoRecording(); CL_DrawHUD( CL_CHANGELEVEL ); diff --git a/engine/client/client.h b/engine/client/client.h index 58ec1177..3adac361 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -962,6 +962,7 @@ void SCR_RSpeeds( void ); void SCR_DrawFPS( int height ); void SCR_DrawPos( void ); void SCR_DrawEnts( void ); +void SCR_DrawUserCmd( void ); // // cl_netgraph.c