blob: ef3cce321705d391655511e40ca07abd4f9d27c2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "point_camera.h"
#include "modelentities.h"
#include "info_camera_link.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
class CFuncMonitor : public CFuncBrush
{
DECLARE_DATADESC();
DECLARE_CLASS( CFuncMonitor, CFuncBrush );
DECLARE_SERVERCLASS();
public:
virtual void Activate();
virtual void UpdateOnRemove();
private:
void InputSetCamera(inputdata_t &inputdata);
void SetCameraByName(const char *szName);
void ReleaseCameraLink();
EHANDLE m_hInfoCameraLink;
};
// automatically hooks in the system's callbacks
BEGIN_DATADESC( CFuncMonitor )
DEFINE_FIELD( m_hInfoCameraLink, FIELD_EHANDLE ),
// Outputs
DEFINE_INPUTFUNC( FIELD_STRING, "SetCamera", InputSetCamera ),
END_DATADESC()
LINK_ENTITY_TO_CLASS( func_monitor, CFuncMonitor );
IMPLEMENT_SERVERCLASS_ST( CFuncMonitor, DT_FuncMonitor )
END_SEND_TABLE()
//-----------------------------------------------------------------------------
// Purpose: Called after all entities have spawned and after a load game.
//-----------------------------------------------------------------------------
void CFuncMonitor::Activate()
{
BaseClass::Activate();
SetCameraByName(STRING(m_target));
}
void CFuncMonitor::UpdateOnRemove()
{
ReleaseCameraLink();
BaseClass::UpdateOnRemove();
}
//-----------------------------------------------------------------------------
// Frees the camera.
//-----------------------------------------------------------------------------
void CFuncMonitor::ReleaseCameraLink()
{
if ( m_hInfoCameraLink )
{
UTIL_Remove( m_hInfoCameraLink );
m_hInfoCameraLink = NULL;
// Keep the target up-to-date for save/load
m_target = NULL_STRING;
}
}
//-----------------------------------------------------------------------------
// Sets camera
//-----------------------------------------------------------------------------
void CFuncMonitor::SetCameraByName(const char *szName)
{
ReleaseCameraLink();
CBaseEntity *pBaseEnt = gEntList.FindEntityByName( NULL, szName );
if( pBaseEnt )
{
CPointCamera *pCamera = dynamic_cast<CPointCamera *>( pBaseEnt );
if( pCamera )
{
// Keep the target up-to-date for save/load
m_target = MAKE_STRING( szName );
m_hInfoCameraLink = CreateInfoCameraLink( this, pCamera );
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CFuncMonitor::InputSetCamera(inputdata_t &inputdata)
{
SetCameraByName( inputdata.value.String() );
}
|