User:JacobsDevelop/GlowArticle

From Valve Developer Community
Jump to navigation Jump to search

Template:WIP


Activation

  • Add GLOWS_ENABLE to the preprocessor directives on your client and server projects (don't forget to add it for release and debug, too!)
  • Add the following line to ClientModeShared::DoPostScreenSpaceEffects:
g_GlowObjectManager.RenderGlowEffects( pSetup, 0 );


Materials Required: SDK2013_TF2_GlowOutlineMaterials.zip


  • Precache the effect by placing this code in clientmode_shared.cpp (search for other references of CLIENTEFFECT_REGISTER_BEGIN for usage example):
CLIENTEFFECT_REGISTER_BEGIN( PrecachePostProcessingEffectsGlow )
CLIENTEFFECT_MATERIAL( "dev/glow_color" )
CLIENTEFFECT_MATERIAL( "dev/halo_add_to_screen" )
CLIENTEFFECT_REGISTER_END_CONDITIONAL( engine->GetDXSupportLevel() >= 90 )

Don't forget to add the include defintion for the precache system!

#include "clienteffectprecachesystem.h"

(Optional) Transferring getters and setters from CBaseCombatCharacter

By default objects derived from CBaseCombatCharacter have getters and setters which can be problematic.
This section shows how to transfer setters and getters from CBaseCombatCharacter to CBaseAnimating since most entities e.g. CBaseCombatCharacter, CDynamicProp, CBaseProp and more.

There are two parts: Server and Client, where we'll start with server first. Firstly delete this part of code from basecombatcharacter.h (lines 415-420) into baseanimating.h:

#ifdef GLOWS_ENABLE
public:
void				AddGlowEffect(void);
void				RemoveGlowEffect(void);
bool				IsGlowEffectActive(void);
#endif

After that, do the same thing to this part of code (basecombatcharacter.h, lines 459-462):

#ifdef GLOWS_ENABLE
CNetworkVar(bool, m_bGlowEnabled);
#endif
Note.pngNote:This part of code needs to be in protected: modifier. If there's no protected modifier make one

And finally repeat that with this part of code (basecombatcharacter.h, lines 467-468)

void				UpdateGlowEffect( void );
void				DestroyGlowEffect( void );
Note.pngNote:This part of code needs to be in private: modifier

Now move to basecombatcharacter.cpp and baseanimating.cpp First part of code to delete from basecombatcharacter.cpp (lines 193-195) and put it into baseanimating.cpp (line 230):

#ifdef GLOWS_ENABLE
SendPropBool( SENDINFO( m_bGlowEnabled ) ),
#endif

Next, from basecombatcharacter.cpp (lines 744-746) put this part of code into baseanimating.cpp CBaseAnimating::CBaseAnimating

#ifdef GLOWS_ENABLE
m_bGlowEnabled.Set( false );
#endif

Lastly delete this from basecombatcharacter.cpp (lines 3227-3252)

#ifdef GLOWS_ENABLE
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseCombatCharacter::AddGlowEffect( void )
{
	SetTransmitState( FL_EDICT_ALWAYS );
	m_bGlowEnabled.Set( true );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseCombatCharacter::RemoveGlowEffect( void )
{
	m_bGlowEnabled.Set( false );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CBaseCombatCharacter::IsGlowEffectActive( void )
{
	return m_bGlowEnabled;
}
#endif // GLOWS_ENABLE

and put this part somewhere under CBaseAnimating::~CBaseAnimating in baseanimating.cpp

#ifdef GLOWS_ENABLE
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseAnimating::AddGlowEffect(void)
{
	SetTransmitState(FL_EDICT_ALWAYS);
	m_bGlowEnabled.Set(true);
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseAnimating::RemoveGlowEffect(void)
{
	m_bGlowEnabled.Set(false);
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CBaseAnimating::IsGlowEffectActive(void)
{
	return m_bGlowEnabled;
}
#endif

This is the end of server part, now onto client part. We'll be mainly operating on two files c_baseanimating.cpp/.h and c_basecombatcharacter.cpp/.h First step

Usage

If you followed this step

To start a glow, call:

myObject->AddGlowEffect(); //Make it glow

To update a glow, call:

myObject->UpdateGlowEffect(); //Update glow

To stop a glow, call:

myObject->RemoveGlowEffect(); //Make it stop glowing