source-sdk-2013-mapbase/sp/src/game/server/env_dof_controller.cpp
Blixibon 87cd9b24bb Mapbase v6.1
- Added postprocess_controller entity from later versions of Source
- Added env_dof_controller entity from later versions of Source
- Added SDK_Engine_Post and DepthOfField shaders from the Momentum repo/Alien Swarm SDK
- Fixed auto-breaking game_text/choreo text not null terminating
- Fixed console groups showing up at the wrong developer levels
- Added more mesages to console groups, including a new "NPC AI" console group
- Fixed typos and added elaboration in various cvars, console messages, etc.
- Fixed npc_metropolice not using frag grenades correctly when allowed to use them
- Fixed npc_metropolice not registering stitching squad slots in AI
- Fixed SetModel input late precache warning
- Fixed env_global_light angles resetting upon loading a save
- Fixed an issue with ScriptKeyValuesRead using the wrong name and having a memory leak
- Allowed VScript functions which return null strings to actually return null instead of empty strings
- Added VScript member variable documentation
- Fixed VScript documentation lines sometimes mixing together
- Fixed VScript singletons having a ! at the beginning of descriptions
- Added Color struct to VScript and allowed color-related inputs to use it
- Added more VScript functions for weapons, ammo, ragdolling, and response contexts
- Added GameRules singleton for VScript
- Exposed AI interaction system to VScript
- Recovered some lost documentation from older revisions of the Mapbase wiki
- Added a way to get the current game's load type in VScript
- Fixed Precache/SpawnEntityFromTable not accounting for a few important field types
- Added VScript functions for getting a player's eye vectors
- Fixed a crash caused by removing the active weapon of a Combine soldier while it's firing
- Changed the way metrocops deploy their manhacks so they could use their manhack death response properly
- Fixed "Use Server" keyvalue on game_convar_mod not working
- Adjusted CAI_Expresser in VScript
2020-12-17 03:38:23 +00:00

187 lines
6.4 KiB
C++

//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
//
// Purpose: Depth of field controller entity
//
//=============================================================================
#include "cbase.h"
#include "baseentity.h"
#include "entityoutput.h"
#include "env_dof_controller.h"
#include "ai_utils.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
LINK_ENTITY_TO_CLASS( env_dof_controller, CEnvDOFController );
BEGIN_DATADESC( CEnvDOFController )
DEFINE_KEYFIELD( m_bDOFEnabled, FIELD_BOOLEAN, "enabled" ),
DEFINE_KEYFIELD( m_flNearBlurDepth, FIELD_FLOAT, "near_blur" ),
DEFINE_KEYFIELD( m_flNearFocusDepth, FIELD_FLOAT, "near_focus" ),
DEFINE_KEYFIELD( m_flFarFocusDepth, FIELD_FLOAT, "far_focus" ),
DEFINE_KEYFIELD( m_flFarBlurDepth, FIELD_FLOAT, "far_blur" ),
DEFINE_KEYFIELD( m_flNearBlurRadius, FIELD_FLOAT, "near_radius" ),
DEFINE_KEYFIELD( m_flFarBlurRadius, FIELD_FLOAT, "far_radius" ),
DEFINE_KEYFIELD( m_strFocusTargetName, FIELD_STRING, "focus_target" ),
DEFINE_KEYFIELD( m_flFocusTargetRange, FIELD_FLOAT, "focus_range" ),
DEFINE_FIELD( m_hFocusTarget, FIELD_EHANDLE ),
DEFINE_THINKFUNC( UpdateParamBlend ),
// Inputs
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetNearBlurDepth", InputSetNearBlurDepth ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetNearFocusDepth", InputSetNearFocusDepth ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFarFocusDepth", InputSetFarFocusDepth ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFarBlurDepth", InputSetFarBlurDepth ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetNearBlurRadius", InputSetNearBlurRadius ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFarBlurRadius", InputSetFarBlurRadius ),
DEFINE_INPUTFUNC( FIELD_STRING, "SetFocusTarget", InputSetFocusTarget ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFocusTargetRange", InputSetFocusTargetRange ),
END_DATADESC()
IMPLEMENT_SERVERCLASS_ST( CEnvDOFController, DT_EnvDOFController )
SendPropInt( SENDINFO(m_bDOFEnabled), 1, SPROP_UNSIGNED ),
SendPropFloat( SENDINFO(m_flNearBlurDepth), 0, SPROP_NOSCALE),
SendPropFloat( SENDINFO(m_flNearFocusDepth), 0, SPROP_NOSCALE),
SendPropFloat( SENDINFO(m_flFarFocusDepth), 0, SPROP_NOSCALE),
SendPropFloat( SENDINFO(m_flFarBlurDepth), 0, SPROP_NOSCALE),
SendPropFloat( SENDINFO(m_flNearBlurRadius), 0, SPROP_NOSCALE),
SendPropFloat( SENDINFO(m_flFarBlurRadius), 0, SPROP_NOSCALE),
END_SEND_TABLE()
void CEnvDOFController::Spawn()
{
SetSolid( SOLID_NONE );
SetMoveType( MOVETYPE_NONE );
#ifdef MAPBASE
// Find our target entity and hold on to it
m_hFocusTarget = gEntList.FindEntityByName( NULL, m_strFocusTargetName, this );
// Update if we have a focal target
if ( m_hFocusTarget )
{
SetThink( &CEnvDOFController::UpdateParamBlend );
SetNextThink( gpGlobals->curtime + 0.1f );
}
#endif
}
void CEnvDOFController::Activate()
{
BaseClass::Activate();
#ifndef MAPBASE // Mapbase moves this to Spawn() to avoid issues with save/restore and entities set via the SetFocusTarget input
// Find our target entity and hold on to it
m_hFocusTarget = gEntList.FindEntityByName( NULL, m_strFocusTargetName );
// Update if we have a focal target
if ( m_hFocusTarget )
{
SetThink( &CEnvDOFController::UpdateParamBlend );
SetNextThink( gpGlobals->curtime + 0.1f );
}
#endif
}
int CEnvDOFController::UpdateTransmitState()
{
return SetTransmitState( FL_EDICT_ALWAYS );
}
void CEnvDOFController::InputSetNearBlurDepth( inputdata_t &inputdata )
{
m_flNearBlurDepth = inputdata.value.Float();
}
void CEnvDOFController::InputSetNearFocusDepth( inputdata_t &inputdata )
{
m_flNearFocusDepth = inputdata.value.Float();
}
void CEnvDOFController::InputSetFarFocusDepth( inputdata_t &inputdata )
{
m_flFarFocusDepth = inputdata.value.Float();
}
void CEnvDOFController::InputSetFarBlurDepth( inputdata_t &inputdata )
{
m_flFarBlurDepth = inputdata.value.Float();
}
void CEnvDOFController::InputSetNearBlurRadius( inputdata_t &inputdata )
{
m_flNearBlurRadius = inputdata.value.Float();
m_bDOFEnabled = ( m_flNearBlurRadius > 0.0f ) || ( m_flFarBlurRadius > 0.0f );
}
void CEnvDOFController::InputSetFarBlurRadius( inputdata_t &inputdata )
{
m_flFarBlurRadius = inputdata.value.Float();
m_bDOFEnabled = ( m_flNearBlurRadius > 0.0f ) || ( m_flFarBlurRadius > 0.0f );
}
void CEnvDOFController::SetControllerState( DOFControlSettings_t setting )
{
m_flNearBlurDepth = setting.flNearBlurDepth;
m_flNearBlurRadius = setting.flNearBlurRadius;
m_flNearFocusDepth = setting.flNearFocusDistance;
m_flFarBlurDepth = setting.flFarBlurDepth;
m_flFarBlurRadius = setting.flFarBlurRadius;
m_flFarFocusDepth = setting.flFarFocusDistance;
m_bDOFEnabled = ( m_flNearBlurRadius > 0.0f ) || ( m_flFarBlurRadius > 0.0f );
}
#define BLUR_DEPTH 500.0f
//-----------------------------------------------------------------------------
// Purpose: Blend the parameters to the specified value
//-----------------------------------------------------------------------------
void CEnvDOFController::UpdateParamBlend()
{
// Update our focal target if we have one
if ( m_hFocusTarget )
{
CBasePlayer *pPlayer = AI_GetSinglePlayer();
float flDistToFocus = ( m_hFocusTarget->GetAbsOrigin() - pPlayer->GetAbsOrigin() ).Length();
m_flFarFocusDepth.GetForModify() = flDistToFocus + m_flFocusTargetRange;
m_flFarBlurDepth.GetForModify() = m_flFarFocusDepth + BLUR_DEPTH;
SetThink( &CEnvDOFController::UpdateParamBlend );
SetNextThink( gpGlobals->curtime + 0.1f );
}
}
//-----------------------------------------------------------------------------
// Purpose: Set the "focus" target entity
//-----------------------------------------------------------------------------
void CEnvDOFController::InputSetFocusTarget( inputdata_t &inputdata )
{
#ifdef MAPBASE
m_hFocusTarget = gEntList.FindEntityByName( NULL, inputdata.value.String(), this, inputdata.pActivator, inputdata.pCaller );
#else
m_hFocusTarget = gEntList.FindEntityByName( NULL, inputdata.value.String() );
#endif
// Update if we have a focal target
if ( m_hFocusTarget )
{
SetThink( &CEnvDOFController::UpdateParamBlend );
SetNextThink( gpGlobals->curtime + 0.1f );
}
}
//-----------------------------------------------------------------------------
// Purpose: Set the range behind the focus entity that we'll blur (in units)
//-----------------------------------------------------------------------------
void CEnvDOFController::InputSetFocusTargetRange( inputdata_t &inputdata )
{
m_flFocusTargetRange = inputdata.value.Float();
}