Skip to content

Commit

Permalink
Stunstick projected texture light
Browse files Browse the repository at this point in the history
  • Loading branch information
1upD committed Oct 24, 2019
1 parent 22f7fa9 commit 7b10c07
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 22 deletions.
2 changes: 1 addition & 1 deletion sp/src/game/client/c_baseplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ void C_BasePlayer::UpdateFlashlight()
{
#ifdef EZ
// Turned on the headlight; create it.
m_pFlashlight = new CFlashlightEffect( true, index );
m_pFlashlight = new CFlashlightEffect( index, NVG );
#else
// Turned on the headlight; create it.
m_pFlashlight = new CFlashlightEffect( index );
Expand Down
43 changes: 30 additions & 13 deletions sp/src/game/client/flashlighteffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ void r_newflashlightCallback_f( IConVar *pConVar, const char *pOldString, float
#ifdef EZ
//-----------------------------------------------------------------------------
// Purpose: Alternate constructor for Entropy : Zero.
// Input : isNVG - Whether or not this flashlight is NVG
// Input : type - flashlight, NVG, or muzzleflash
// nEntIndex - The m_nEntIndex of the client entity that is creating us.
// vecPos - The position of the light emitter.
// vecDir - The direction of the light emission.
//-----------------------------------------------------------------------------
CFlashlightEffect::CFlashlightEffect( int nEntIndex, bool isNVG )
CFlashlightEffect::CFlashlightEffect( int nEntIndex, flashlighttype type )
#else
//-----------------------------------------------------------------------------
// Purpose:
Expand All @@ -92,12 +92,12 @@ CFlashlightEffect::CFlashlightEffect(int nEntIndex)
r_newflashlight.SetValue( 0 );
}
#ifdef EZ
this->m_bIsNVG = isNVG;
if ( g_pMaterialSystemHardwareConfig->SupportsBorderColor() && isNVG )
m_iFlashLightType = type;
if ( g_pMaterialSystemHardwareConfig->SupportsBorderColor() && IsNVG() )
{
m_FlashlightTexture.Init( "effects/Ez_MetroVision_border", TEXTURE_GROUP_OTHER, true );
}
else if ( isNVG )
else if ( IsNVG() )
{
m_FlashlightTexture.Init( "effects/Ez_MetroVision", TEXTURE_GROUP_OTHER, true );
}
Expand Down Expand Up @@ -183,21 +183,32 @@ class CTraceFilterSkipPlayerAndViewModel : public CTraceFilter
}
};

extern ConVar cl_stunstick_flashlight_distance;
extern ConVar cl_stunstick_flashlight_intensity;

//-----------------------------------------------------------------------------
// Purpose: Do the headlight
//-----------------------------------------------------------------------------
void CFlashlightEffect::UpdateLightNew(const Vector &vecPos, const Vector &vecForward, const Vector &vecRight, const Vector &vecUp )
{
float fov;
float fov, flashlightFar;

#ifdef EZ
if ( IsNVG() )
if ( m_iFlashLightType == NVG )
{
fov = r_nvgfov.GetFloat();
fov = r_nvgfov.GetFloat();
flashlightFar = r_flashlightfar.GetFloat();
}
else if ( m_iFlashLightType == MUZZLEFLASH )
{
fov = 179;
flashlightFar = cl_stunstick_flashlight_distance.GetFloat();
}
else
#endif
{
fov = r_flashlightfov.GetFloat();
flashlightFar = r_flashlightfar.GetFloat();
}


Expand Down Expand Up @@ -249,7 +260,7 @@ void CFlashlightEffect::UpdateLightNew(const Vector &vecPos, const Vector &vecFo
iMask &= ~CONTENTS_HITBOX;
iMask |= CONTENTS_WINDOW;

Vector vTarget = vecPos + vecForward * r_flashlightfar.GetFloat();
Vector vTarget = vecPos + vecForward * flashlightFar;

// Work with these local copies of the basis for the rest of the function
Vector vDir = vTarget - vOrigin;
Expand Down Expand Up @@ -371,15 +382,22 @@ void CFlashlightEffect::UpdateLightNew(const Vector &vecPos, const Vector &vecFo
}

state.m_fConstantAtten = r_flashlightconstant.GetFloat();
#ifndef EZ
state.m_Color[0] = 1.0f;
state.m_Color[1] = 1.0f;
state.m_Color[2] = 1.0f;
#else
state.m_Color[0] = m_iFlashLightType == MUZZLEFLASH ? cl_stunstick_flashlight_intensity.GetFloat() : 1.0f;
state.m_Color[1] = m_iFlashLightType == MUZZLEFLASH ? cl_stunstick_flashlight_intensity.GetFloat() : 1.0f;
state.m_Color[2] = m_iFlashLightType == MUZZLEFLASH ? cl_stunstick_flashlight_intensity.GetFloat() : 1.0f;
#endif

state.m_Color[3] = r_flashlightambient.GetFloat();
state.m_NearZ = r_flashlightnear.GetFloat() + m_flDistMod; // Push near plane out so that we don't clip the world when the flashlight pulls back
state.m_FarZ = r_flashlightfar.GetFloat();
state.m_FarZ = flashlightFar;
#ifdef EZ
// The NVG projected texture should not cast shadows
state.m_bEnableShadows = !IsNVG() && r_flashlightdepthtexture.GetBool();
state.m_bEnableShadows = m_iFlashLightType == FLASHLIGHT && r_flashlightdepthtexture.GetBool();
#else
state.m_bEnableShadows = r_flashlightdepthtexture.GetBool();
#endif
Expand Down Expand Up @@ -599,5 +617,4 @@ void CHeadlightEffect::UpdateLight( const Vector &vecPos, const Vector &vecDir,
}

g_pClientShadowMgr->UpdateProjectedTexture( GetFlashlightHandle(), true );
}

}
19 changes: 13 additions & 6 deletions sp/src/game/client/flashlighteffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@

struct dlight_t;

#ifdef EZ
enum flashlighttype
{
FLASHLIGHT,
NVG,
MUZZLEFLASH
};
#endif

class CFlashlightEffect
{
public:

#ifdef EZ
CFlashlightEffect( int nEntIndex = 0, bool isNVG = false );
CFlashlightEffect( int nEntIndex = 0, flashlighttype type = FLASHLIGHT );
#else
CFlashlightEffect(int nEntIndex = 0);
#endif
Expand All @@ -33,7 +41,7 @@ class CFlashlightEffect
void SetFlashlightHandle( ClientShadowHandle_t Handle ) { m_FlashlightHandle = Handle; }

#ifdef EZ
virtual bool IsNVG( void ) { return m_bIsNVG; }
virtual bool IsNVG( void ) { return m_iFlashLightType == NVG; }
#endif
protected:

Expand All @@ -55,8 +63,9 @@ class CFlashlightEffect
// Texture for flashlight
CTextureReference m_FlashlightTexture;

// Is this flashlight an NVG?
bool m_bIsNVG;
#ifdef EZ
flashlighttype m_iFlashLightType;
#endif
};

class CHeadlightEffect : public CFlashlightEffect
Expand All @@ -69,6 +78,4 @@ class CHeadlightEffect : public CFlashlightEffect
virtual void UpdateLight(const Vector &vecPos, const Vector &vecDir, const Vector &vecRight, const Vector &vecUp, int nDistance);
};



#endif // FLASHLIGHTEFFECT_H
68 changes: 67 additions & 1 deletion sp/src/game/shared/hl2mp/weapon_stunstick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ CWeaponStunStick::CWeaponStunStick( void )
#ifdef CLIENT_DLL
m_bSwungLastFrame = false;
m_flFadeTime = FADE_DURATION; // Start off past the fade point
m_pStunstickLight = NULL;
#endif
}

Expand Down Expand Up @@ -959,7 +960,9 @@ void C_WeaponStunStick::DrawFirstPersonEffects( void )
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if ( pPlayer != NULL )
{
pPlayer->DoMuzzleFlash();
m_flLastMuzzleFlashTime = gpGlobals->curtime;
//// Not using actual muzzle flashes for now
//pPlayer->DoMuzzleFlash();
}
}
#endif
Expand Down Expand Up @@ -1036,6 +1039,69 @@ void C_WeaponStunStick::ViewModelDrawn( C_BaseViewModel *pBaseViewModel )
BaseClass::ViewModelDrawn( pBaseViewModel );
}

#ifdef EZ

ConVar cl_stunstick_flashlight ( "cl_stunstick_flashlight", "1" );
ConVar cl_stunstick_flashlight_distance ( "cl_stunstick_flashlight", "512" );
ConVar cl_stunstick_flashlight_intensity ( "cl_stunstick_flashlight_intensity", "0.1" );

//// Not using actual muzzle flashes for now
//void C_WeaponStunStick::ProcessMuzzleFlashEvent()
//{
// if (ShouldDrawUsingViewModel())
// {
// m_flLastMuzzleFlashTime = gpGlobals->curtime;
// return;
// }
//
// BaseClass::ProcessMuzzleFlashEvent();
//}

// Override Simulate() to handle stunstick projected texture
void C_WeaponStunStick::Simulate( void )
{
if ( cl_stunstick_flashlight.GetBool() )
{
bool stunstickLight = gpGlobals->curtime < m_flLastMuzzleFlashTime + 0.05f;

// The dim light is the flashlight.
if (stunstickLight)
{
if (m_pStunstickLight == NULL)
{
// Turned on the headlight; create it.
m_pStunstickLight = new CFlashlightEffect( 0, MUZZLEFLASH );

if (m_pStunstickLight == NULL)
return;

m_pStunstickLight->TurnOn();
}

if (GetOwner()->IsPlayer())
{
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if (pPlayer != NULL)
{
Vector vecForward, vecRight, vecUp;
pPlayer->EyeVectors( &vecForward, &vecRight, &vecUp );
m_pStunstickLight->UpdateLight( EyePosition(), vecForward, vecRight, vecUp, cl_stunstick_flashlight_distance.GetFloat() );
}
}
}
else if (m_pStunstickLight)
{
m_pStunstickLight->TurnOff();
// Turned off the flashlight; delete it.
delete m_pStunstickLight;
m_pStunstickLight = NULL;
}
}

BaseClass::Simulate();
}
#endif

//-----------------------------------------------------------------------------
// Purpose: Draw a cheap glow quad at our impact point (with sparks)
//-----------------------------------------------------------------------------
Expand Down
20 changes: 19 additions & 1 deletion sp/src/game/shared/hl2mp/weapon_stunstick.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
#ifdef CLIENT_DLL
#define CWeaponStunStick C_WeaponStunStick
#define CBaseHLBludgeonWeapon C_BaseHLBludgeonWeapon

#ifdef EZ
#include "flashlighteffect.h"
#endif

#endif

#ifndef HL2MP
Expand Down Expand Up @@ -59,7 +64,20 @@ class CWeaponStunStick : public CBaseHL2MPBludgeonWeapon
virtual void OnDataChanged( DataUpdateType_t updateType );
virtual RenderGroup_t GetRenderGroup( void );
virtual void ViewModelDrawn( C_BaseViewModel *pBaseViewModel );


#ifdef EZ
// This is called to do the actual muzzle flash effect.
//void ProcessMuzzleFlashEvent();
void Simulate( void );

protected:
float m_flLastMuzzleFlashTime;

CFlashlightEffect *m_pStunstickLight;

public:
#endif

#endif

virtual void Precache();
Expand Down

0 comments on commit 7b10c07

Please sign in to comment.