Skip to content

Commit 4797e03

Browse files
committed
Add clientside nodraw networking workaround
Made to prevent the CC exclusion mask from drawing beams when disabled, but designed with general use in mind
1 parent 07b87f9 commit 4797e03

9 files changed

Lines changed: 90 additions & 0 deletions

File tree

sp/src/game/client/c_baseentity.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3710,7 +3710,9 @@ void C_BaseEntity::ComputeFxBlend( void )
37103710
//-----------------------------------------------------------------------------
37113711
int C_BaseEntity::GetFxBlend( void )
37123712
{
3713+
#ifndef MAPBASE // Spams the console when drawing beams in stencils, which don't need to update the FX blend
37133714
Assert( m_nFXComputeFrame == gpGlobals->framecount );
3715+
#endif
37143716
return m_nRenderFXBlend;
37153717
}
37163718

sp/src/game/client/clientmode_shared.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,22 @@ static void __MsgFunc_VGUIMenu( bf_read &msg )
282282
gViewPortInterface->ShowPanel( viewport, bShow );
283283
}
284284

285+
#ifdef MAPBASE
286+
static void __MsgFunc_NodrawToggle( bf_read &msg )
287+
{
288+
C_BaseEntity *pEntity = C_BaseEntity::Instance( msg.ReadShort() );
289+
bool bEnable = msg.ReadOneBit();
290+
291+
if ( pEntity )
292+
{
293+
if ( bEnable )
294+
pEntity->AddEffects( EF_NODRAW );
295+
else
296+
pEntity->RemoveEffects( EF_NODRAW );
297+
}
298+
}
299+
#endif
300+
285301
//-----------------------------------------------------------------------------
286302
// Purpose:
287303
//-----------------------------------------------------------------------------
@@ -387,6 +403,9 @@ void ClientModeShared::Init()
387403

388404
HOOK_MESSAGE( VGUIMenu );
389405
HOOK_MESSAGE( Rumble );
406+
#ifdef MAPBASE
407+
HOOK_MESSAGE( NodrawToggle );
408+
#endif
390409
}
391410

392411

sp/src/game/server/baseentity.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4404,6 +4404,30 @@ void CBaseEntity::SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways )
44044404
}
44054405

44064406

4407+
#ifdef MAPBASE
4408+
//-----------------------------------------------------------------------------
4409+
// Purpose: If true, this entity will notify clients when EF_NODRAW is set.
4410+
// This is mainly a band-aid for when the client paradoxically wants
4411+
// to know this.
4412+
//-----------------------------------------------------------------------------
4413+
void CBaseEntity::OnNodrawToggled()
4414+
{
4415+
if ( ShouldNetworkNodraw() )
4416+
{
4417+
// MP TODO: Optimize who receives this message?
4418+
CRecipientFilter filter;
4419+
filter.AddAllPlayers();
4420+
filter.MakeReliable();
4421+
4422+
UserMessageBegin( filter, "NodrawToggle" );
4423+
WRITE_ENTITY( entindex() );
4424+
WRITE_BOOL( IsEffectActive( EF_NODRAW ) );
4425+
MessageEnd();
4426+
}
4427+
}
4428+
#endif
4429+
4430+
44074431
//-----------------------------------------------------------------------------
44084432
// Returns which skybox the entity is in
44094433
//-----------------------------------------------------------------------------

sp/src/game/server/baseentity.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,13 @@ class CBaseEntity : public IServerEntity
559559
void SetSimulatedEveryTick( bool sim );
560560
void SetAnimatedEveryTick( bool anim );
561561

562+
#ifdef MAPBASE
563+
// If true, this entity will notify clients when EF_NODRAW is set.
564+
// This is mainly a band-aid for when the client paradoxically wants to know this.
565+
virtual bool ShouldNetworkNodraw() { return false; }
566+
void OnNodrawToggled();
567+
#endif
568+
562569
public:
563570

564571
virtual const char *GetTracerType( void );

sp/src/game/shared/baseentity_shared.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ void CBaseEntity::SetEffects( int nEffects )
224224
#endif // HL2_EPISODIC
225225
#endif // !CLIENT_DLL
226226

227+
#if defined(MAPBASE) && !defined(CLIENT_DLL)
228+
// Nodraw was added or removed
229+
if ( (m_fEffects ^ nEffects) & EF_NODRAW )
230+
OnNodrawToggled();
231+
#endif
232+
227233
m_fEffects = nEffects;
228234

229235
#ifndef CLIENT_DLL
@@ -255,6 +261,9 @@ void CBaseEntity::AddEffects( int nEffects )
255261
{
256262
#ifndef CLIENT_DLL
257263
DispatchUpdateTransmitState();
264+
#ifdef MAPBASE
265+
OnNodrawToggled();
266+
#endif
258267
#else
259268
UpdateVisibility();
260269
#endif

sp/src/game/shared/baseentity_shared.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ inline void CBaseEntity::RemoveEffects( int nEffects )
216216
#ifndef CLIENT_DLL
217217
NetworkProp()->MarkPVSInformationDirty();
218218
DispatchUpdateTransmitState();
219+
#ifdef MAPBASE
220+
OnNodrawToggled();
221+
#endif
219222
#else
220223
UpdateVisibility();
221224
#endif

sp/src/game/shared/beam_shared.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ BEGIN_DATADESC( CBeam )
278278

279279
DEFINE_KEYFIELD( m_nDissolveType, FIELD_INTEGER, "dissolvetype" ),
280280

281+
#ifdef MAPBASE
282+
DEFINE_FIELD( m_bNetworkNodraw, FIELD_BOOLEAN ),
283+
#endif
284+
281285
#ifdef PORTAL
282286
DEFINE_FIELD( m_bDrawInMainRender, FIELD_BOOLEAN ),
283287
DEFINE_FIELD( m_bDrawInPortalRender, FIELD_BOOLEAN ),
@@ -918,6 +922,16 @@ int CBeam::ShouldTransmit( const CCheckTransmitInfo *pInfo )
918922
return BaseClass::ShouldTransmit( pInfo );
919923
}
920924

925+
#ifdef MAPBASE
926+
bool CBeam::ShouldNetworkNodraw()
927+
{
928+
if ( m_bNetworkNodraw )
929+
return true;
930+
931+
return BaseClass::ShouldNetworkNodraw();
932+
}
933+
#endif
934+
921935
#endif
922936

923937
//-----------------------------------------------------------------------------

sp/src/game/shared/beam_shared.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ class CBeam : public CBaseEntity
6464
void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
6565
int UpdateTransmitState( void );
6666
int ShouldTransmit( const CCheckTransmitInfo *pInfo );
67+
#ifdef MAPBASE
68+
bool ShouldNetworkNodraw();
69+
void SetNetworkNodraw( bool bToggle ) { m_bNetworkNodraw = bToggle; }
70+
#endif
6771
#endif
6872

6973
virtual int DrawDebugTextOverlays(void);
@@ -235,6 +239,10 @@ class CBeam : public CBaseEntity
235239

236240
#if !defined( CLIENT_DLL )
237241
int m_nDissolveType;
242+
243+
#ifdef MAPBASE
244+
bool m_bNetworkNodraw;
245+
#endif
238246
#endif
239247

240248
public:

sp/src/game/shared/mapbase/mapbase_usermessages.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ void HookMapbaseUserMessages( void )
2222
//HOOK_MESSAGE( ScriptMsg ); // Hooked in CNetMsgScriptHelper
2323

2424
//HOOK_MESSAGE( ShowMenuComplex ); // Hooked in CHudMenu
25+
26+
//HOOK_MESSAGE( NodrawToggle ); // Hooked in ClientModeShared
2527
}
2628
#endif
2729

@@ -31,6 +33,8 @@ void RegisterMapbaseUserMessages( void )
3133
usermessages->Register( "ScriptMsg", -1 ); // CNetMsgScriptHelper
3234

3335
usermessages->Register( "ShowMenuComplex", -1 ); // CHudMenu
36+
37+
usermessages->Register( "NodrawToggle", 3 ); // ClientModeShared
3438

3539
#ifdef CLIENT_DLL
3640
// TODO: Better placement?

0 commit comments

Comments
 (0)