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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: A camera entity that's used by the -makedevshots system to take
// dev screenshots everytime the map is checked into source control.
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "tier0/icommandline.h"
#include "igamesystem.h"
#include "filesystem.h"
#include <KeyValues.h>
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
int g_iDevShotCameraCount = 0;
#define DEVSHOT_INITIAL_WAIT 5 // Time after the level spawn before the first devshot camera takes it's shot
#define DEVSHOT_INTERVAL 5 // Time between each devshot camera taking it's shot
//-----------------------------------------------------------------------------
// Purpose: A camera entity that's used by the -makedevshots system to take
// dev screenshots everytime the map is checked into source control.
//-----------------------------------------------------------------------------
class CPointDevShotCamera : public CBaseEntity
{
DECLARE_CLASS( CPointDevShotCamera, CBaseEntity );
public:
DECLARE_DATADESC();
void Spawn( void );
void DevShotThink_Setup( void );
void DevShotThink_TakeShot( void );
void DevShotThink_PostShot( void );
// Always transmit to clients so they know where to move the view to
virtual int UpdateTransmitState();
private:
string_t m_iszCameraName;
int m_iFOV;
};
BEGIN_DATADESC( CPointDevShotCamera )
DEFINE_FUNCTION( DevShotThink_Setup ),
DEFINE_FUNCTION( DevShotThink_TakeShot ),
DEFINE_FUNCTION( DevShotThink_PostShot ),
DEFINE_KEYFIELD( m_iszCameraName, FIELD_STRING, "cameraname" ),
DEFINE_KEYFIELD( m_iFOV, FIELD_INTEGER, "FOV" ),
END_DATADESC()
LINK_ENTITY_TO_CLASS( point_devshot_camera, CPointDevShotCamera );
//-----------------------------------------------------------------------------
// Purpose: Convenience function so we don't have to make this check all over
//-----------------------------------------------------------------------------
static CBasePlayer * UTIL_GetLocalPlayerOrListenServerHost( void )
{
if ( gpGlobals->maxClients > 1 )
{
if ( engine->IsDedicatedServer() )
{
return NULL;
}
return UTIL_GetListenServerHost();
}
return UTIL_GetLocalPlayer();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPointDevShotCamera::Spawn( void )
{
BaseClass::Spawn();
// Remove this entity immediately if we're not making devshots
if ( !CommandLine()->FindParm("-makedevshots") )
{
UTIL_Remove( this );
return;
}
// Take a screenshot when it's my turn
SetThink( &CPointDevShotCamera::DevShotThink_Setup );
SetNextThink( gpGlobals->curtime + DEVSHOT_INITIAL_WAIT + (g_iDevShotCameraCount * DEVSHOT_INTERVAL) );
g_iDevShotCameraCount++;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CPointDevShotCamera::UpdateTransmitState()
{
// always transmit if currently used by a monitor
return SetTransmitState( FL_EDICT_ALWAYS );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPointDevShotCamera::DevShotThink_Setup( void )
{
// Move the player to the devshot camera
CBasePlayer *pPlayer = UTIL_GetLocalPlayerOrListenServerHost();
if ( !pPlayer )
return;
// Hide stuff
engine->ClientCommand( pPlayer->edict(), "developer 0" );
engine->ClientCommand( pPlayer->edict(), "cl_drawhud 0" );
engine->ClientCommand( pPlayer->edict(), "sv_cheats 1" );
engine->ClientCommand( pPlayer->edict(), "god" );
engine->ClientCommand( pPlayer->edict(), "notarget" );
pPlayer->AddSolidFlags( FSOLID_NOT_SOLID );
pPlayer->EnableControl(FALSE);
pPlayer->SetViewEntity( this );
pPlayer->SetFOV( this, m_iFOV );
// Hide the player's viewmodel
if ( pPlayer->GetActiveWeapon() )
{
pPlayer->GetActiveWeapon()->AddEffects( EF_NODRAW );
}
DispatchUpdateTransmitState();
// Now take the shot next frame
SetThink( &CPointDevShotCamera::DevShotThink_TakeShot );
SetNextThink( gpGlobals->curtime );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPointDevShotCamera::DevShotThink_TakeShot( void )
{
// Take the screenshot
CBasePlayer *pPlayer = UTIL_GetLocalPlayerOrListenServerHost();
if ( !pPlayer )
return;
engine->ClientCommand( pPlayer->edict(), "devshots_screenshot \"%s\"", STRING(m_iszCameraName) );
// Now take the shot next frame
SetThink( &CPointDevShotCamera::DevShotThink_PostShot );
SetNextThink( gpGlobals->curtime + (DEVSHOT_INTERVAL - 1) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPointDevShotCamera::DevShotThink_PostShot( void )
{
// Take the screenshot
CBasePlayer *pPlayer = UTIL_GetLocalPlayerOrListenServerHost();
if ( !pPlayer )
return;
pPlayer->SetFOV( this, 0 );
// If all cameras have taken their shots, move to the next map
g_iDevShotCameraCount--;
if ( !g_iDevShotCameraCount )
{
engine->ClientCommand( pPlayer->edict(), "devshots_nextmap" );
}
}
//-----------------------------------------------------------------------------
// Purpose: Game system to detect maps without cameras in them, and move on
//-----------------------------------------------------------------------------
class CDevShotSystem : public CAutoGameSystemPerFrame
{
public:
CDevShotSystem( char const *name ) : CAutoGameSystemPerFrame( name )
{
}
virtual void LevelInitPreEntity()
{
m_bIssuedNextMapCommand = false;
g_iDevShotCameraCount = 0;
m_bParsedMapFile = false;
}
virtual void SafeRemoveIfDesired( void )
{
// If we're not making devshots, remove this system immediately
if ( !CommandLine()->FindParm("-makedevshots") )
{
Remove( this );
return;
}
}
virtual void FrameUpdatePostEntityThink( void )
{
// Wait until we're all spawned in
if ( gpGlobals->curtime < 5 )
return;
if ( m_bIssuedNextMapCommand )
return;
if ( !m_bParsedMapFile )
{
m_bParsedMapFile = true;
// See if we've got a camera file to import cameras from
char szFullName[512];
Q_snprintf(szFullName,sizeof(szFullName), "maps/%s.txt", STRING( gpGlobals->mapname ));
KeyValues *pkvMapCameras = new KeyValues( "MapCameras" );
if ( pkvMapCameras->LoadFromFile( filesystem, szFullName, "MOD" ) )
{
Warning( "Devshots: Loading point_devshot_camera positions from %s. \n", szFullName );
// Get each camera, and add it to our list
KeyValues *pkvCamera = pkvMapCameras->GetFirstSubKey();
while ( pkvCamera )
{
// Get camera name
const char *pCameraName = pkvCamera->GetName();
// Make a camera, and move it to the position specified
CPointDevShotCamera *pCamera = (CPointDevShotCamera*)CreateEntityByName( "point_devshot_camera" );
Assert( pCamera );
pCamera->KeyValue( "cameraname", pCameraName );
pCamera->KeyValue( "origin", pkvCamera->GetString( "origin", "0 0 0" ) );
pCamera->KeyValue( "angles", pkvCamera->GetString( "angles", "0 0 0" ) );
pCamera->KeyValue( "FOV", pkvCamera->GetString( "FOV", "75" ) );
DispatchSpawn( pCamera );
pCamera->Activate();
// Move to next camera
pkvCamera = pkvCamera->GetNextKey();
}
}
if ( !g_iDevShotCameraCount )
{
Warning( "Devshots: No point_devshot_camera in %s. Moving to next map.\n", STRING( gpGlobals->mapname ) );
CBasePlayer *pPlayer = UTIL_GetLocalPlayerOrListenServerHost();
if ( pPlayer )
{
engine->ClientCommand( pPlayer->edict(), "devshots_nextmap" );
m_bIssuedNextMapCommand = true;
return;
}
}
}
}
private:
bool m_bIssuedNextMapCommand;
bool m_bParsedMapFile;
};
CDevShotSystem DevShotSystem( "CDevShotSystem" );
|