From fe3644a4175db73c02298911e1453b41e77268c6 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 22 Jun 2024 08:16:48 +0300 Subject: [PATCH] engine: client: add simple debugging tool that shows entities number, model and movetype (to be extended) --- engine/client/cl_scrn.c | 68 ++++++++++++++++++++++++++++++++++++++++- engine/client/cl_view.c | 1 + engine/client/client.h | 1 + 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index ca44be6e..c8b046bc 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -32,6 +32,7 @@ CVAR_DEFINE_AUTO( v_dark, "0", 0, "starts level from dark screen" ); 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)" ); typedef struct { @@ -122,7 +123,7 @@ void SCR_DrawPos( void ) if( cls.state != ca_active || !cl_showpos.value || cl.background ) return; - ent = CL_GetLocalPlayer(); + ent = CL_EDICT_NUM( cl.playernum + 1 ); speed = VectorLength( cl.simvel ); Q_snprintf( msg, MAX_SYSPATH, @@ -140,6 +141,68 @@ void SCR_DrawPos( void ) Con_DrawString( refState.width / 2, 4, msg, color ); } +/* +============== +SCR_DrawEnts +============== +*/ +void SCR_DrawEnts( void ) +{ + rgba_t color = { 255, 255, 255, 255 }; + int i; + + if( cls.state != ca_active || !cl_showents.value || ( cl.maxclients > 1 && !cls.demoplayback )) + return; + + // this probably better hook CL_AddVisibleEntities + // as entities might get added by client.dll + for( i = 0; i < clgame.maxEntities; i++ ) + { + const cl_entity_t *ent = &clgame.entities[i]; + string msg; + vec3_t screen, pos; + + if( ent->curstate.messagenum != cl.parsecount ) + continue; + + VectorCopy( ent->origin, pos ); + + if( ent->model != NULL ) + { + vec3_t v; + + // simple model type filter + if( cl_showents.value > 1 ) + { + if( ent->model->type != (modtype_t)( cl_showents.value - 2 )) + continue; + } + + VectorAverage( ent->model->mins, ent->model->maxs, v ); + VectorAdd( pos, v, pos ); + } + + if( !ref.dllFuncs.WorldToScreen( pos, screen )) + { + Q_snprintf( msg, sizeof( msg ), + "entity %d\n" + "model %s\n" + "movetype %d\n", + ent->index, + ent->model ? ent->model->name : "(null)", + ent->curstate.movetype ); + + screen[0] = 0.5f * screen[0] * refState.width; + screen[1] = -0.5f * screen[1] * refState.height; + screen[0] += 0.5f * refState.width; + screen[1] += 0.5f * refState.height; + + + Con_DrawString( screen[0], screen[1], msg, color ); + } + } +} + /* ============== SCR_NetSpeeds @@ -753,6 +816,9 @@ void SCR_Init( void ) Cvar_RegisterVariable( &net_speeds ); Cvar_RegisterVariable( &cl_showfps ); Cvar_RegisterVariable( &cl_showpos ); +#ifdef _DEBUG + Cvar_RegisterVariable( &cl_showents ); +#endif // NDEBUG // register our commands Cmd_AddCommand( "skyname", CL_SetSky_f, "set new skybox by basename" ); diff --git a/engine/client/cl_view.c b/engine/client/cl_view.c index 4058d25e..7ead100d 100644 --- a/engine/client/cl_view.c +++ b/engine/client/cl_view.c @@ -532,6 +532,7 @@ void V_PostRender( void ) SCR_RSpeeds(); SCR_NetSpeeds(); SCR_DrawPos(); + SCR_DrawEnts(); SCR_DrawNetGraph(); SV_DrawOrthoTriangles(); CL_DrawDemoRecording(); diff --git a/engine/client/client.h b/engine/client/client.h index d2813331..6d818988 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -925,6 +925,7 @@ void SCR_NetSpeeds( void ); void SCR_RSpeeds( void ); void SCR_DrawFPS( int height ); void SCR_DrawPos( void ); +void SCR_DrawEnts( void ); // // cl_netgraph.c