BHit performance improvements

Use ray trace directly instead of build-in drawline command.
This commit is contained in:
Kawe Mazidjatari 2023-01-22 12:09:12 +01:00
parent d7f3209525
commit a281768ac9
4 changed files with 29 additions and 9 deletions

View File

@ -119,6 +119,7 @@ void ConVar::Init(void)
#endif // DEDICATED
#endif // !CLIENT_DLL
#if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1)
bhit_zbuffer = ConVar::Create("bhit_zbuffer" , "1", FCVAR_DEVELOPMENTONLY | FCVAR_REPLICATED, "Use z-buffer for bullet ray trace overlay.", false, 0.f, false, 0.f, nullptr, nullptr);
bhit_abs_origin = ConVar::Create("bhit_abs_origin", "1", FCVAR_DEVELOPMENTONLY | FCVAR_REPLICATED, "Draw entity's predicted abs origin upon bullet impact for trajectory debugging.", false, 0.f, false, 0.f, nullptr, nullptr);
#endif // !GAMEDLL_S0 && !GAMEDLL_S1
//-------------------------------------------------------------------------
@ -254,6 +255,8 @@ void ConVar::InitShipped(void)
#ifndef DEDICATED
rui_defaultDebugFontFace = g_pCVar->FindVar("rui_defaultDebugFontFace");
#endif // !DEDICATED
r_visualizetraces = g_pCVar->FindVar("r_visualizetraces");
r_visualizetraces_duration = g_pCVar->FindVar("r_visualizetraces_duration");
staticProp_no_fade_scalar = g_pCVar->FindVar("staticProp_no_fade_scalar");
staticProp_gather_size_weight = g_pCVar->FindVar("staticProp_gather_size_weight");
stream_overlay = g_pCVar->FindVar("stream_overlay");

View File

@ -41,6 +41,11 @@ ConVar* r_drawWorldMeshes = nullptr;
ConVar* r_drawWorldMeshesDepthOnly = nullptr;
ConVar* r_drawWorldMeshesDepthAtTheEnd = nullptr;
#ifndef DEDICATED
ConVar* r_visualizetraces = nullptr;
ConVar* r_visualizetraces_duration = nullptr;
#endif // !DEDICATED
ConVar* stream_overlay = nullptr;
ConVar* stream_overlay_mode = nullptr;
//-----------------------------------------------------------------------------
@ -90,6 +95,7 @@ ConVar* sv_visualizetraces = nullptr;
ConVar* sv_visualizetraces_duration = nullptr;
#if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1)
ConVar* bhit_enable = nullptr;
ConVar* bhit_zbuffer = nullptr;
ConVar* bhit_abs_origin = nullptr;
#endif // !GAMEDLL_S0 && !GAMEDLL_S1
//-----------------------------------------------------------------------------

View File

@ -38,6 +38,11 @@ extern ConVar* r_drawWorldMeshes;
extern ConVar* r_drawWorldMeshesDepthOnly;
extern ConVar* r_drawWorldMeshesDepthAtTheEnd;
#ifndef DEDICATED
extern ConVar* r_visualizetraces;
extern ConVar* r_visualizetraces_duration;
#endif // !DEDICATED
extern ConVar* stream_overlay;
extern ConVar* stream_overlay_mode;
//-------------------------------------------------------------------------
@ -86,6 +91,7 @@ extern ConVar* sv_visualizetraces;
extern ConVar* sv_visualizetraces_duration;
#if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1)
extern ConVar* bhit_enable;
extern ConVar* bhit_zbuffer;
extern ConVar* bhit_abs_origin;
#endif // !GAMEDLL_S0 && !GAMEDLL_S1
//-------------------------------------------------------------------------

View File

@ -19,6 +19,7 @@
#include "engine/net.h"
#include "engine/host_cmd.h"
#include "engine/host_state.h"
#include "engine/enginetrace.h"
#ifndef CLIENT_DLL
#include "engine/server/server.h"
#endif // !CLIENT_DLL
@ -47,6 +48,8 @@
#include "vstdlib/callback.h"
#ifndef DEDICATED
#include "materialsystem/cmaterialglue.h"
#include "public/bspflags.h"
#include "public/cmodel.h"
#include "public/idebugoverlay.h"
#endif // !DEDICATED
#ifndef CLIENT_DLL
@ -1161,21 +1164,23 @@ void BHit_f(const CCommand& args)
vecBulletAngles.z = 180.f; // Flipped axis.
AngleVectors(vecBulletAngles, &vecAbsEnd);
static char szBuf[2048]; // Render physics trace.
snprintf(szBuf, sizeof(szBuf), "drawline %g %g %g %g %g %g",
vecAbsStart.x, vecAbsStart.y, vecAbsStart.z,
vecAbsStart.x + vecAbsEnd.x * MAX_COORD_RANGE,
vecAbsStart.y + vecAbsEnd.y * MAX_COORD_RANGE,
vecAbsStart.z + vecAbsEnd.z * MAX_COORD_RANGE);
Cbuf_AddText(Cbuf_GetCurrentPlayer(), szBuf, cmd_source_t::kCommandSrcCode);
vecAbsEnd.MulAdd(vecAbsStart, vecAbsEnd, MAX_COORD_RANGE);
if (bhit_abs_origin->GetBool())
Ray_t ray(vecAbsStart, vecAbsEnd);
trace_t trace;
g_pEngineTraceServer->TraceRay(ray, TRACE_MASK_NPCWORLDSTATIC, &trace);
g_pDebugOverlay->AddLineOverlay(trace.startpos, trace.endpos, 0, 255, 0, bhit_zbuffer->GetBool(), sv_visualizetraces_duration->GetFloat());
g_pDebugOverlay->AddLineOverlay(trace.endpos, vecAbsEnd, 255, 0, 0, bhit_zbuffer->GetBool(), sv_visualizetraces_duration->GetFloat());
if (bhit_abs_origin->GetBool() && r_visualizetraces->GetBool())
{
const int iEnt = atoi(args[2]);
if (const IClientEntity* pEntity = g_pClientEntityList->GetClientEntity(iEnt))
{
g_pDebugOverlay->AddSphereOverlay( // Render a debug sphere at the client's predicted entity origin.
pEntity->GetAbsOrigin(), 10.f, 8, 6, 20, 60, 255, 0, sv_visualizetraces_duration->GetFloat());
pEntity->GetAbsOrigin(), 10.f, 8, 6, 20, 60, 255, 0, r_visualizetraces_duration->GetFloat());
}
}
#endif // !DEDICATED