User:JacobsDevelop/GlowArticle: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
(seems finished)
Tag: Replaced
 
(12 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{WIP|[[User:JacobsDevelop|JacobsDevelop]] ([[User talk:JacobsDevelop|talk]])}}
{{messagebox|text=This was a "prototype" page for grand rework of [[TF2_Glow_Effect_(2013_SDK)|this page]]. Now it's just there}}
{{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__
 
=Activation=
 
* Add {{Key|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''':
 
<source lang=cpp>
g_GlowObjectManager.RenderGlowEffects( pSetup, 0 );
</source>
 
 
'''Materials Required:'''
[https://www.dropbox.com/s/ltyomrglekrhriv/sdk2013_tf2_glowoutlinematerials.zip?dl=0 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):
 
<source lang=cpp>
CLIENTEFFECT_REGISTER_BEGIN( PrecachePostProcessingEffectsGlow )
CLIENTEFFECT_MATERIAL( "dev/glow_color" )
CLIENTEFFECT_MATERIAL( "dev/halo_add_to_screen" )
CLIENTEFFECT_REGISTER_END_CONDITIONAL( engine->GetDXSupportLevel() >= 90 )
</source>
 
Don't forget to add the include defintion for the precache system!
<source lang=cpp>
#include "clienteffectprecachesystem.h"
</source>
 
=(Optional) Transferring getters and setters from CBaseCombatCharacter=
{{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=
 
If you followed [[#.28Optional.29_Transferring_getters_and_setters_from_CBaseCombatCharacter|this step]]
 
To start a glow, call:
<source lang=cpp>
myObject->AddGlowEffect(); //Make it glow
</source>
 
To update a glow, call:
<source lang=cpp>
myObject->UpdateGlowEffect(); //Update glow
</source>
 
To stop a glow, call:
<source lang=cpp>
myObject->RemoveGlowEffect(); //Make it stop glowing
</source>
 
[[Category:Programming]]
[[Category:Snippets]]

Latest revision as of 20:04, 21 April 2025