Skip to content

Commit edb0214

Browse files
authored
DebugDrawLine grenade trails for spectators and practicing (#1852)
* working using debugdralines * clamp and float and stuff
1 parent ad13ea5 commit edb0214

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

src/game/shared/sdk/sdk_basegrenade_projectile.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ float GetCurrentGravity( void );
1414

1515
#ifndef NEO
1616
#include "c_sdk_player.h"
17+
#else
18+
#include "neo_gamerules.h"
1719
#endif // NEO
1820
#else
1921

@@ -42,7 +44,14 @@ BEGIN_NETWORK_TABLE( CBaseGrenadeProjectile, DT_BaseGrenadeProjectile )
4244
END_NETWORK_TABLE()
4345

4446

47+
#ifdef NEO
48+
ConVar sv_neo_grenade_show_path("sv_neo_grenade_show_path", "0", FCVAR_REPLICATED | FCVAR_CHEAT, "Whether to show a grenade's path to all players, and for how long", true, 0, true, 15.f);
49+
#endif // NEO
4550
#ifdef CLIENT_DLL
51+
#ifdef NEO
52+
// We're not clearing the debug overlay atm, make sure this is very short
53+
ConVar cl_neo_grenade_show_path("cl_neo_grenade_show_path", "0", FCVAR_ARCHIVE | FCVAR_USERINFO, "Whether to show a grenade's path when spectating, and for how long", true, 0, true, 2.f);
54+
#endif // NEO
4655

4756

4857
void CBaseGrenadeProjectile::PostDataUpdate( DataUpdateType_t type )
@@ -127,6 +136,48 @@ END_NETWORK_TABLE()
127136
{
128137
SetNextClientThink(gpGlobals->curtime + TICK_INTERVAL);
129138
}
139+
if (cl_neo_grenade_show_path.GetBool() || sv_neo_grenade_show_path.GetBool())
140+
{
141+
DrawPath();
142+
SetNextClientThink(gpGlobals->curtime + TICK_INTERVAL);
143+
}
144+
}
145+
146+
void CBaseGrenadeProjectile::DrawPath()
147+
{
148+
CBasePlayer *player = UTIL_PlayerByIndex(GetLocalPlayerIndex());
149+
if ( player == NULL )
150+
return;
151+
152+
const bool showPathInSpec = cl_neo_grenade_show_path.GetBool() && player->GetTeamNumber() == TEAM_SPECTATOR;
153+
const bool showPathWhenServerEnabled = sv_neo_grenade_show_path.GetBool();
154+
if (!showPathInSpec && !showPathWhenServerEnabled)
155+
return;
156+
157+
const Vector origin = GetAbsOrigin();
158+
if (!m_vLastDrawPosition.IsValid())
159+
{
160+
m_vLastDrawPosition = origin;
161+
return;
162+
}
163+
164+
if (m_vLastDrawPosition.DistToSqr(origin) < 0.1f)
165+
return;
166+
167+
float r = 0, g = 0, b = 0;
168+
NEORules()->GetTeamGlowColor(GetTeamNumber(), r, g, b);
169+
r *= 255;
170+
g *= 255;
171+
b *= 255;
172+
if (GetDamage())
173+
{
174+
const float timeAlive = (gpGlobals->curtime - m_flNeoCreateTime) * 0.5f;
175+
r = clamp(r * (1 - timeAlive) + (255.f * timeAlive), 0.f, 255.f);
176+
g = clamp(g * (1 - timeAlive), 0.f, 255.f);
177+
b = clamp(b * (1 - timeAlive), 0.f, 255.f);
178+
}
179+
DebugDrawLine(m_vLastDrawPosition, origin, r, g, b, true, showPathWhenServerEnabled ? sv_neo_grenade_show_path.GetFloat() : cl_neo_grenade_show_path.GetFloat());
180+
m_vLastDrawPosition = origin;
130181
}
131182
#endif // NEO
132183

@@ -142,6 +193,15 @@ END_NETWORK_TABLE()
142193

143194
// smaller, cube bounding box so we rest on the ground
144195
SetSize( Vector ( -2, -2, -2 ), Vector ( 2, 2, 2 ) );
196+
197+
if (sv_neo_grenade_show_path.GetBool())
198+
{ // Transmit the grenade to all players so they can see the path outside their pvs
199+
SetTransmitState(FL_EDICT_ALWAYS);
200+
}
201+
else
202+
{ // Spectators will still want to see the grenade if they have cl_neo_grenade_show_path set
203+
SetTransmitState(FL_EDICT_FULLCHECK);
204+
}
145205
}
146206

147207
void CBaseGrenadeProjectile::DangerSoundThink( void )

src/game/shared/sdk/sdk_basegrenade_projectile.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class CBaseGrenadeProjectile : public CBaseGrenade
4343
#ifdef NEO
4444
virtual void ClientThink() override;
4545
float m_flTemperature;
46+
private:
47+
void DrawPath();
48+
Vector m_vLastDrawPosition = Vector(VEC_T_NAN, VEC_T_NAN, VEC_T_NAN);
49+
public:
4650
#endif // NEO
4751
float m_flSpawnTime;
4852
#else
@@ -63,6 +67,21 @@ class CBaseGrenadeProjectile : public CBaseGrenade
6367
// sit still until it had gotten a few updates from the server.
6468
void SetupInitialTransmittedGrenadeVelocity( const Vector &velocity );
6569

70+
int ShouldTransmit(const CCheckTransmitInfo* pInfo) override
71+
{
72+
CBaseEntity *pRecipientEntity = CBaseEntity::Instance( pInfo->m_pClientEnt );
73+
74+
if ( pRecipientEntity && pRecipientEntity->GetTeamNumber() == TEAM_SPECTATOR )
75+
{
76+
const char* wantsToSeeProjectilePath = engine->GetClientConVarValue(pRecipientEntity->entindex(), "cl_neo_grenade_show_path");
77+
if (wantsToSeeProjectilePath && *wantsToSeeProjectilePath && (V_atof(wantsToSeeProjectilePath) != 0.f))
78+
{
79+
return FL_EDICT_ALWAYS;
80+
}
81+
}
82+
return FL_EDICT_PVSCHECK;
83+
}
84+
6685
protected:
6786

6887
#ifdef NEO

0 commit comments

Comments
 (0)