summaryrefslogtreecommitdiff
path: root/engine/DevShotGenerator.cpp
blob: c6bf6f003886dee4473cce91530c287f878a8bce (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
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#include "DevShotGenerator.h"
#include "cmd.h"
#include "fmtstr.h"
#include "host.h"
#include "tier0/icommandline.h"
#include <tier0/dbg.h>

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

#define PAUSE_FRAMES_BETWEEN_MAPS	300
#define PAUSE_TIME_BETWEEN_MAPS		2.0f

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void DevShotGenerator_Usage()
{
	// 
	Msg( "-makedevshots usage:\n" );
	Msg( "  [ -usedevshotsfile filename ] -- get map list from specified file, default is to build for maps/*.bsp\n" );
	Msg( "  [ -startmap mapname ] -- restart generation at specified map (after crash, implies resume)\n" );
	Msg( "  [ -condebug ] -- prepend console.log entries with mapname or engine if not in a map\n" );
	Msg( "  [ +map mapname ] -- generate devshots for specified map and exit after that map\n" );
}

void DevShotGenerator_Init()
{
	// check for devshot generation
	if ( CommandLine()->FindParm("-makedevshots") )
	{
		bool usemaplistfile = false;
		if ( CommandLine()->FindParm("-usedevshotsfile") )
		{
			usemaplistfile = true;
		}
		DevShotGenerator().EnableDevShotGeneration( usemaplistfile );
	}
}

void DevShotGenerator_Shutdown()
{
	DevShotGenerator().Shutdown();
}

void DevShotGenerator_BuildMapList()
{
	DevShotGenerator().BuildMapList();
}

CDevShotGenerator g_DevShotGenerator;
CDevShotGenerator &DevShotGenerator()
{
	return g_DevShotGenerator;
}

void CL_DevShots_NextMap()
{
	DevShotGenerator().NextMap();
}

static ConCommand devshots_nextmap( "devshots_nextmap", CL_DevShots_NextMap, "Used by the devshots system to go to the next map in the devshots maplist." );

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CDevShotGenerator::CDevShotGenerator() 
{
	m_bUsingMapList = false;
	m_bDevShotsEnabled = false;
	m_iCurrentMap = 0;
}

void CDevShotGenerator::BuildMapList()
{
	if ( !m_bDevShotsEnabled )
		return;

	DevShotGenerator_Usage();

	// Get the maplist file, if any
	const char *pMapFile = NULL;
	CommandLine()->CheckParm( "-usedevshotsfile", &pMapFile );

	// Build the map list
	if ( !BuildGeneralMapList( &m_Maps, CommandLine()->FindParm("-usedevshotsfile") != 0, pMapFile, "devshots", &m_iCurrentMap ) )
	{
		m_bDevShotsEnabled = false;
	}
}

void CDevShotGenerator::NextMap()
{
	if ( !m_bDevShotsEnabled )
		return;

	//Msg("DEVSHOTS: Nextmap command received.\n");

	if (m_Maps.IsValidIndex(m_iCurrentMap))
	{
		//Msg("DEVSHOTS: Switching to %s (%d).\n", m_Maps[m_iCurrentMap].name, m_iCurrentMap );
		CFmtStr str("map %s\n", m_Maps[m_iCurrentMap].name);
		Cbuf_AddText( str.Access() );

		++m_iCurrentMap;
	}
	else
	{
		//Msg("DEVSHOTS: Finished on map %d.\n", m_iCurrentMap);

		// no more levels, just quit
		Cbuf_AddText( "quit\n" );
	}
}

//-----------------------------------------------------------------------------
// Purpose: initializes the object to enable dev shot generation
//-----------------------------------------------------------------------------
void CDevShotGenerator::EnableDevShotGeneration( bool usemaplistfile )
{
	m_bUsingMapList = usemaplistfile;
	m_bDevShotsEnabled = true;
}

//-----------------------------------------------------------------------------
// Purpose: starts the first map
//-----------------------------------------------------------------------------
void CDevShotGenerator::StartDevShotGeneration()
{
	BuildMapList();

	CFmtStr str("map %s\n", m_Maps[m_iCurrentMap].name);
	Cbuf_AddText( str.Access() );
	++m_iCurrentMap;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDevShotGenerator::Shutdown()
{
}