User:JacobsDevelop/GlowArticle: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{WIP|[[User:JacobsDevelop|JacobsDevelop]] ([[User talk:JacobsDevelop|talk]])}}
{{WIP|[[User:JacobsDevelop|JacobsDevelop]] ([[User talk:JacobsDevelop|talk]])}}
{{messagebox|text=This page is candidate to replace contents of [[TF2_Glow_Effect_(2013_SDK)|this page]]. Any suggestions are appreciated [[User talk:JacobsDevelop|here]]}}


__FORCETOC__
__FORCETOC__
Line 32: Line 33:


=(Optional) Transferring getters and setters from CBaseCombatCharacter=
=(Optional) Transferring getters and setters from CBaseCombatCharacter=
{{Important|This part is quite long, but fortunately most of this part is just copying/pasting code from one file to another with small changes}}
{{Expand|
By default objects derived from {{Key|CBaseCombatCharacter}} have getters and setters which can be problematic. <br>This section shows how to transfer setters and getters from {{Key|CBaseCombatCharacter}} to {{Key|CBaseAnimating}} since most entities e.g. {{Key|CBaseCombatCharacter}}, {{Key|CDynamicProp}}, {{Key|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''':
<source lang=cpp>
#ifdef GLOWS_ENABLE
public:
void AddGlowEffect(void);
void RemoveGlowEffect(void);
bool IsGlowEffectActive(void);
#endif
</source>
After that, do the same thing to this part of code ('''basecombatcharacter.h''', lines 459-462):
<source lang=cpp>
#ifdef GLOWS_ENABLE
CNetworkVar(bool, m_bGlowEnabled);
#endif
</source>
{{Note|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)
<source lang=cpp>
void UpdateGlowEffect( void );
void DestroyGlowEffect( void );
</source>
{{Note|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):
<source lang=cpp>
#ifdef GLOWS_ENABLE
SendPropBool( SENDINFO( m_bGlowEnabled ) ),
#endif
</source>
Next, from '''basecombatcharacter.cpp''' (lines 744-746) put this part of code into '''baseanimating.cpp''' '''CBaseAnimating::CBaseAnimating'''
<source lang=cpp>
#ifdef GLOWS_ENABLE
m_bGlowEnabled.Set( false );
#endif
</source>
Lastly delete this from '''basecombatcharacter.cpp''' (lines 3227-3252)
<source lang=cpp>
#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
</source>
and put this part somewhere under '''CBaseAnimating::~CBaseAnimating''' in '''baseanimating.cpp'''
<source lang=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
</source>
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=
=Usage=



Revision as of 12:30, 22 April 2022

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