User:JacobsDevelop/GlowArticle: Difference between revisions
No edit summary |
mNo edit summary |
||
Line 33: | Line 33: | ||
=(Optional) Transferring getters and setters from CBaseCombatCharacter= | =(Optional) Transferring getters and setters from CBaseCombatCharacter= | ||
{{ | {{Important|This part is completely optional if you're okay with how glow works by default you can skip to [[#Usage|usage]] section.}} | ||
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. | 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 are derived from {{Key|CBaseAnimating}} e.g. {{Key|CBaseCombatCharacter}}, {{Key|CDynamicProp}}, {{Key|CBaseProp}} and more. | ||
There are two parts: Server and Client, where we'll start with server first. | 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''': | Firstly delete this part of code from '''basecombatcharacter.h''' (lines 415-420) and put it into '''baseanimating.h''' (recommended lines 54-58): | ||
<source lang=cpp> | <source lang=cpp> | ||
#ifdef GLOWS_ENABLE | #ifdef GLOWS_ENABLE | ||
Line 47: | Line 47: | ||
</source> | </source> | ||
After that, do the same thing to this part of code ('''basecombatcharacter.h''', lines 459-462): | After that, do the same thing to this part of code ('''basecombatcharacter.h''', lines 459-462, '''baseanimating.h''' recommended lines 171-174): | ||
<source lang=cpp> | <source lang=cpp> | ||
#ifdef GLOWS_ENABLE | #ifdef GLOWS_ENABLE | ||
protected: | |||
CNetworkVar(bool, m_bGlowEnabled); | CNetworkVar(bool, m_bGlowEnabled); | ||
#endif | #endif | ||
Line 55: | Line 56: | ||
{{Note|This part of code needs to be in '''protected:''' modifier. If there's no protected modifier make one}} | {{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) | And finally repeat that with this part of code ('''basecombatcharacter.h''', lines 467-468, '''baseanimating.h''' recommended lines 355-356) | ||
<source lang=cpp> | <source lang=cpp> | ||
void UpdateGlowEffect( void ); | void UpdateGlowEffect( void ); | ||
Line 138: | Line 139: | ||
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''' | 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''' | ||
Firstly delete this part from '''c_basecombatcharacter.h''' (lines 17-19) and put at the top of '''c_baseanimating.h''' | |||
}} | <source lang=cpp> | ||
#ifdef GLOWS_ENABLE | |||
#include "glow_outline_effect.h" | |||
#endif | |||
</source> | |||
Secondly is to delete this part of code from '''c_basecombatcharacter.h''' (lines 94-97) and put it into '''c_baseanimating.h''' (recommended lines 149-152) | |||
<source lang=cpp> | |||
#ifdef GLOWS_ENABLE | |||
CGlowObject *GetGlowObject( void ){ return m_pGlowEffect; } | |||
virtual void GetGlowEffectColor( float *r, float *g, float *b ); | |||
#endif // GLOWS_ENABLE | |||
</source> | |||
Then repeat that for this for this part of code (from '''c_basecombatcharacter.h''', lines 100-103 to '''c_baseanimating.h''', recommended lines 458-461): | |||
<source lang=cpp> | |||
#ifdef GLOWS_ENABLE | |||
virtual void UpdateGlowEffect(void); | |||
virtual void DestroyGlowEffect(void); | |||
#endif // GLOWS_ENABLE | |||
</source> | |||
And this (from '''c_basecombatcharacter.h''', lines 110-114 to '''c_baseanimating.h''', recommended lines 481-485): | |||
<source lang=cpp> | |||
#ifdef GLOWS_ENABLE | |||
bool m_bGlowEnabled; | |||
bool m_bOldGlowEnabled; | |||
CGlowObject *m_pGlowEffect; | |||
#endif | |||
</source> | |||
Now go into '''c_basecombatcharacter.cpp''' and '''c_baseanimating.cpp''' | |||
Firstly delete this part of code from '''c_basecombatcharacter.cpp''' (lines 33-37) and put it into '''c_baseanimating.cpp''' (recommended lines 737-741): | |||
<source lang=cpp> | |||
#ifdef GLOWS_ENABLE | |||
m_pGlowEffect = NULL; | |||
m_bGlowEnabled = false; | |||
m_bOldGlowEnabled = false; | |||
#endif // GLOWS_ENABLE | |||
</source> | |||
Then delete this part of code from '''C_BaseCombatCharacter::~C_BaseCombatCharacter''' and put it into '''C_BaseAnimating::~C_BaseAnimating''' | |||
<source lang=cpp> | |||
#ifdef GLOWS_ENABLE | |||
DestroyGlowEffect(); | |||
#endif // GLOWS_ENABLE | |||
</source> | |||
and repeat this for this part of code (from '''c_basecombatcharacter.h''', lines 58-60 to '''c_baseanimating.h''', recommended lines 4528-4530): | |||
<source lang=cpp> | |||
#ifdef GLOWS_ENABLE | |||
m_bOldGlowEnabled = m_bGlowEnabled; | |||
#endif // GLOWS_ENABLE | |||
</source> | |||
and again (from '''c_basecombatcharacter.h''', lines 66-71 to '''c_baseanimating.h''', recommended lines 4716-4721): | |||
<source lang=cpp> | |||
#ifdef GLOWS_ENABLE | |||
m_bOldGlowEnabled = m_bGlowEnabled; | |||
#endif // GLOWS_ENABLE | |||
</source> | |||
Remove this section of code from '''c_basecombatcharacter.h''' (lines 85-128) | |||
<source lang=cpp> | |||
#ifdef GLOWS_ENABLE | |||
//----------------------------------------------------------------------------- | |||
// Purpose: | |||
//----------------------------------------------------------------------------- | |||
void C_BaseCombatCharacter::GetGlowEffectColor( float *r, float *g, float *b ) | |||
{ | |||
*r = 0.76f; | |||
*g = 0.76f; | |||
*b = 0.76f; | |||
} | |||
//----------------------------------------------------------------------------- | |||
// Purpose: | |||
//----------------------------------------------------------------------------- | |||
void C_BaseCombatCharacter::UpdateGlowEffect( void ) | |||
{ | |||
// destroy the existing effect | |||
if ( m_pGlowEffect ) | |||
{ | |||
DestroyGlowEffect(); | |||
} | |||
// create a new effect | |||
if ( m_bGlowEnabled ) | |||
{ | |||
float r, g, b; | |||
GetGlowEffectColor( &r, &g, &b ); | |||
m_pGlowEffect = new CGlowObject( this, Vector( r, g, b ), 1.0, true ); | |||
} | |||
} | |||
//----------------------------------------------------------------------------- | |||
// Purpose: | |||
//----------------------------------------------------------------------------- | |||
void C_BaseCombatCharacter::DestroyGlowEffect( void ) | |||
{ | |||
if ( m_pGlowEffect ) | |||
{ | |||
delete m_pGlowEffect; | |||
m_pGlowEffect = NULL; | |||
} | |||
} | |||
#endif // GLOWS_ENABLE | |||
</source> | |||
and put this section in '''c_baseanimating.h''' (recommended start on line 4387): | |||
<source lang=cpp> | |||
#ifdef GLOWS_ENABLE | |||
//----------------------------------------------------------------------------- | |||
// Purpose: | |||
//----------------------------------------------------------------------------- | |||
void C_BaseAnimating::GetGlowEffectColor( float *r, float *g, float *b ) | |||
{ | |||
*r = 0.76f; | |||
*g = 0.76f; | |||
*b = 0.76f; | |||
} | |||
//----------------------------------------------------------------------------- | |||
// Purpose: | |||
//----------------------------------------------------------------------------- | |||
void C_BaseAnimating::UpdateGlowEffect( void ) | |||
{ | |||
// destroy the existing effect | |||
if ( m_pGlowEffect ) | |||
{ | |||
DestroyGlowEffect(); | |||
} | |||
// create a new effect | |||
if ( m_bGlowEnabled ) | |||
{ | |||
float r, g, b; | |||
GetGlowEffectColor( &r, &g, &b ); | |||
m_pGlowEffect = new CGlowObject( this, Vector( r, g, b ), 1.0, true ); | |||
} | |||
} | |||
//----------------------------------------------------------------------------- | |||
// Purpose: | |||
//----------------------------------------------------------------------------- | |||
void C_BaseAnimating::DestroyGlowEffect( void ) | |||
{ | |||
if ( m_pGlowEffect ) | |||
{ | |||
delete m_pGlowEffect; | |||
m_pGlowEffect = NULL; | |||
} | |||
} | |||
#endif // GLOWS_ENABLE | |||
</source> | |||
and lastly get this part of code from '''c_basecombatcharacter.cpp''' (lines 97-99) and put it into '''c_baseanimating.cpp''' (recommended lines 150-153): | |||
<source lang=cpp> | |||
#ifdef GLOWS_ENABLE | |||
RecvPropBool( RECVINFO( m_bGlowEnabled ) ), | |||
#endif // GLOWS_ENABLE | |||
</source> | |||
And you're done. Now you can create entities with glow (e.g. prop_dynamic, npcs, etc.) as long as they're derived from {{Key|CBaseAnimating}} onwards. | |||
{{Todo|I plan to add control by inputs/output and also color control, but it'll take some time}} | |||
=Usage= | =Usage= | ||
No matter if you have followed [[#.28Optional.29_Transferring_getters_and_setters_from_CBaseCombatCharacter|this]] or if you had just enabled glow usage is the same with only difference being that if you haven't followed [[#.28Optional.29_Transferring_getters_and_setters_from_CBaseCombatCharacter|this step]] then you can only use setters and getters on objects that are derived from {{Key|CBaseCombatCharacter}} onwards, however if you followed additional step you can use setters and getters for objects derived from {{Key|CBaseAnimating}} onwards. | |||
To start a glow, call: | To start a glow, call: |
Revision as of 13:10, 22 April 2022
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 are derived from CBaseAnimating 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) and put it into baseanimating.h (recommended lines 54-58):
#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, baseanimating.h recommended lines 171-174):
#ifdef GLOWS_ENABLE
protected:
CNetworkVar(bool, m_bGlowEnabled);
#endif

And finally repeat that with this part of code (basecombatcharacter.h, lines 467-468, baseanimating.h recommended lines 355-356)
void UpdateGlowEffect( void );
void DestroyGlowEffect( void );

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 Firstly delete this part from c_basecombatcharacter.h (lines 17-19) and put at the top of c_baseanimating.h
#ifdef GLOWS_ENABLE
#include "glow_outline_effect.h"
#endif
Secondly is to delete this part of code from c_basecombatcharacter.h (lines 94-97) and put it into c_baseanimating.h (recommended lines 149-152)
#ifdef GLOWS_ENABLE
CGlowObject *GetGlowObject( void ){ return m_pGlowEffect; }
virtual void GetGlowEffectColor( float *r, float *g, float *b );
#endif // GLOWS_ENABLE
Then repeat that for this for this part of code (from c_basecombatcharacter.h, lines 100-103 to c_baseanimating.h, recommended lines 458-461):
#ifdef GLOWS_ENABLE
virtual void UpdateGlowEffect(void);
virtual void DestroyGlowEffect(void);
#endif // GLOWS_ENABLE
And this (from c_basecombatcharacter.h, lines 110-114 to c_baseanimating.h, recommended lines 481-485):
#ifdef GLOWS_ENABLE
bool m_bGlowEnabled;
bool m_bOldGlowEnabled;
CGlowObject *m_pGlowEffect;
#endif
Now go into c_basecombatcharacter.cpp and c_baseanimating.cpp Firstly delete this part of code from c_basecombatcharacter.cpp (lines 33-37) and put it into c_baseanimating.cpp (recommended lines 737-741):
#ifdef GLOWS_ENABLE
m_pGlowEffect = NULL;
m_bGlowEnabled = false;
m_bOldGlowEnabled = false;
#endif // GLOWS_ENABLE
Then delete this part of code from C_BaseCombatCharacter::~C_BaseCombatCharacter and put it into C_BaseAnimating::~C_BaseAnimating
#ifdef GLOWS_ENABLE
DestroyGlowEffect();
#endif // GLOWS_ENABLE
and repeat this for this part of code (from c_basecombatcharacter.h, lines 58-60 to c_baseanimating.h, recommended lines 4528-4530):
#ifdef GLOWS_ENABLE
m_bOldGlowEnabled = m_bGlowEnabled;
#endif // GLOWS_ENABLE
and again (from c_basecombatcharacter.h, lines 66-71 to c_baseanimating.h, recommended lines 4716-4721):
#ifdef GLOWS_ENABLE
m_bOldGlowEnabled = m_bGlowEnabled;
#endif // GLOWS_ENABLE
Remove this section of code from c_basecombatcharacter.h (lines 85-128)
#ifdef GLOWS_ENABLE
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_BaseCombatCharacter::GetGlowEffectColor( float *r, float *g, float *b )
{
*r = 0.76f;
*g = 0.76f;
*b = 0.76f;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_BaseCombatCharacter::UpdateGlowEffect( void )
{
// destroy the existing effect
if ( m_pGlowEffect )
{
DestroyGlowEffect();
}
// create a new effect
if ( m_bGlowEnabled )
{
float r, g, b;
GetGlowEffectColor( &r, &g, &b );
m_pGlowEffect = new CGlowObject( this, Vector( r, g, b ), 1.0, true );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_BaseCombatCharacter::DestroyGlowEffect( void )
{
if ( m_pGlowEffect )
{
delete m_pGlowEffect;
m_pGlowEffect = NULL;
}
}
#endif // GLOWS_ENABLE
and put this section in c_baseanimating.h (recommended start on line 4387):
#ifdef GLOWS_ENABLE
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_BaseAnimating::GetGlowEffectColor( float *r, float *g, float *b )
{
*r = 0.76f;
*g = 0.76f;
*b = 0.76f;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_BaseAnimating::UpdateGlowEffect( void )
{
// destroy the existing effect
if ( m_pGlowEffect )
{
DestroyGlowEffect();
}
// create a new effect
if ( m_bGlowEnabled )
{
float r, g, b;
GetGlowEffectColor( &r, &g, &b );
m_pGlowEffect = new CGlowObject( this, Vector( r, g, b ), 1.0, true );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_BaseAnimating::DestroyGlowEffect( void )
{
if ( m_pGlowEffect )
{
delete m_pGlowEffect;
m_pGlowEffect = NULL;
}
}
#endif // GLOWS_ENABLE
and lastly get this part of code from c_basecombatcharacter.cpp (lines 97-99) and put it into c_baseanimating.cpp (recommended lines 150-153):
#ifdef GLOWS_ENABLE
RecvPropBool( RECVINFO( m_bGlowEnabled ) ),
#endif // GLOWS_ENABLE
And you're done. Now you can create entities with glow (e.g. prop_dynamic, npcs, etc.) as long as they're derived from CBaseAnimating onwards.
Usage
No matter if you have followed this or if you had just enabled glow usage is the same with only difference being that if you haven't followed this step then you can only use setters and getters on objects that are derived from CBaseCombatCharacter onwards, however if you followed additional step you can use setters and getters for objects derived from CBaseAnimating onwards.
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