1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-01-04 00:23:25 +08:00
hl2sdk/dlls/env_projectedtexture.cpp

134 lines
3.9 KiB
C++

//====== Copyright © 1996-2003, Valve Corporation, All rights reserved. =======
//
// Purpose: Entity to control screen overlays on a player
//
//=============================================================================
#include "cbase.h"
#include "shareddefs.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define ENV_PROJECTEDTEXTURE_STARTON (1<<0)
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CEnvProjectedTexture : public CPointEntity
{
DECLARE_CLASS( CEnvProjectedTexture, CPointEntity );
public:
DECLARE_DATADESC();
DECLARE_SERVERCLASS();
CEnvProjectedTexture();
// Always transmit to clients
virtual int UpdateTransmitState();
virtual void Activate( void );
void InputTurnOn( inputdata_t &inputdata );
void InputTurnOff( inputdata_t &inputdata );
void InputSetFOV( inputdata_t &inputdata );
void InitialThink( void );
CNetworkHandle( CBaseEntity, m_hTargetEntity );
private:
CNetworkVar( bool, m_bState );
CNetworkVar( float, m_flLightFOV );
CNetworkVar( bool, m_bEnableShadows );
CNetworkVar( bool, m_bLightOnlyTarget );
CNetworkVar( bool, m_bLightWorld );
CNetworkVar( bool, m_bCameraSpace );
CNetworkVar( color32, m_cLightColor );
};
LINK_ENTITY_TO_CLASS( env_projectedtexture, CEnvProjectedTexture );
BEGIN_DATADESC( CEnvProjectedTexture )
DEFINE_FIELD( m_hTargetEntity, FIELD_EHANDLE ),
DEFINE_FIELD( m_bState, FIELD_BOOLEAN ),
DEFINE_KEYFIELD( m_flLightFOV, FIELD_FLOAT, "lightfov" ),
DEFINE_KEYFIELD( m_bEnableShadows, FIELD_BOOLEAN, "enableshadows" ),
DEFINE_KEYFIELD( m_bLightOnlyTarget, FIELD_BOOLEAN, "lightonlytarget" ),
DEFINE_KEYFIELD( m_bLightWorld, FIELD_BOOLEAN, "lightworld" ),
DEFINE_KEYFIELD( m_bCameraSpace, FIELD_BOOLEAN, "cameraspace" ),
DEFINE_KEYFIELD( m_cLightColor, FIELD_COLOR32, "lightcolor" ),
DEFINE_INPUTFUNC( FIELD_VOID, "TurnOn", InputTurnOn ),
DEFINE_INPUTFUNC( FIELD_VOID, "TurnOff", InputTurnOff ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFOV", InputSetFOV ),
DEFINE_THINKFUNC( InitialThink ),
END_DATADESC()
IMPLEMENT_SERVERCLASS_ST( CEnvProjectedTexture, DT_EnvProjectedTexture )
SendPropEHandle( SENDINFO( m_hTargetEntity ) ),
SendPropBool( SENDINFO( m_bState ) ),
SendPropFloat( SENDINFO( m_flLightFOV ) ),
SendPropBool( SENDINFO( m_bEnableShadows ) ),
SendPropBool( SENDINFO( m_bLightOnlyTarget ) ),
SendPropBool( SENDINFO( m_bLightWorld ) ),
SendPropBool( SENDINFO( m_bCameraSpace ) ),
SendPropInt( SENDINFO( m_cLightColor ), 32, SPROP_UNSIGNED ),
END_SEND_TABLE()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CEnvProjectedTexture::CEnvProjectedTexture( void )
{
m_bState = false;
m_flLightFOV = 45.0f;
m_bEnableShadows = false;
m_bLightOnlyTarget = false;
m_bLightWorld = true;
m_bCameraSpace = true;
color32 color;
color.r = 255;
color.g = 255;
color.b = 255;
color.a = 0;
m_cLightColor.Set( color );
}
void CEnvProjectedTexture::InputTurnOn( inputdata_t &inputdata )
{
m_bState = true;
}
void CEnvProjectedTexture::InputTurnOff( inputdata_t &inputdata )
{
m_bState = false;
}
void CEnvProjectedTexture::InputSetFOV( inputdata_t &inputdata )
{
m_flLightFOV = inputdata.value.Float();
}
void CEnvProjectedTexture::Activate( void )
{
if ( GetSpawnFlags() & ENV_PROJECTEDTEXTURE_STARTON )
{
m_bState = true;
}
SetThink( &CEnvProjectedTexture::InitialThink );
SetNextThink( gpGlobals->curtime + 0.1f );
BaseClass::Activate();
}
void CEnvProjectedTexture::InitialThink( void )
{
m_hTargetEntity = gEntList.FindEntityByName( NULL, m_target );
}
int CEnvProjectedTexture::UpdateTransmitState()
{
return SetTransmitState( FL_EDICT_ALWAYS );
}