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

#include "replay_internal.h"
#include "replay/ireplaysystem.h"
#include "replayserver.h"
#include "vgui/ILocalize.h"
#include "server.h"

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

//----------------------------------------------------------------------------------------

IReplaySystem *g_pReplay = NULL;

//----------------------------------------------------------------------------------------

static CSysModule				*gs_hReplayModule = NULL;

IServerReplayContext			*g_pServerReplayContext = NULL;
CreateInterfaceFn				g_fnReplayFactory = NULL;

#if !defined( DEDICATED )
IReplayManager					*g_pReplayManager = NULL;
IReplayMovieRenderer			*g_pReplayMovieRenderer = NULL;
IReplayPerformanceManager		*g_pReplayPerformanceManager = NULL;
IReplayPerformanceController	*g_pReplayPerformanceController = NULL;
IReplayMovieManager				*g_pReplayMovieManager = NULL;
#endif

//----------------------------------------------------------------------------------------

ConVar replay_debug( "replay_debug", "0", FCVAR_DONTRECORD );
	
//----------------------------------------------------------------------------------------

// If you modify this list, you will also need to add the following line to the game's
// client_*.vpc and server_*.vpc files:
//
//    $include "$SRCDIR\vpc_scripts\source_replay.vpc"
//
static const char *s_pSupportedReplayGames[] =
{
	"tf",
	"tf_beta",
};

//----------------------------------------------------------------------------------------

void ReplaySystem_Init( bool bDedicated )
{
#if defined( REPLAY_ENABLED )
	COM_TimestampedLog( "Loading replay.dll" );

	extern IFileSystem *g_pFileSystem;

	// Load the replay DLL
	const char *szDllName = "replay" DLL_EXT_STRING;
	gs_hReplayModule = g_pFileSystem->LoadModule( szDllName );
	g_fnReplayFactory = Sys_GetFactory( gs_hReplayModule );
	if ( !g_fnReplayFactory )
	{
		Error( "Could not load: %s\n", szDllName );
	}
	
	// Get a ptr to the IReplay instance
	g_pReplay = (IReplaySystem *)g_fnReplayFactory( REPLAY_INTERFACE_VERSION, NULL );
	if ( !g_pReplay )
	{
		Error( "Could not get IReplay interface %s from %s\n", REPLAY_INTERFACE_VERSION, szDllName );
	}

	// Initialize the replay DLL
	COM_TimestampedLog( "g_pReplay->Initialize()" );

	extern CreateInterfaceFn g_AppSystemFactory;
	if ( !g_pReplay->Connect( g_AppSystemFactory ) )
	{
		Error( "Connect on replay.dll failed!\n" );
	}

	// Cache some pointers
	g_pServerReplayContext = g_pReplay->SV_GetContext();

	if ( !bDedicated )
	{
		// Add replay localization text files
		extern vgui::ILocalize *g_pVGuiLocalize;
		if ( g_pVGuiLocalize )
		{
			g_pVGuiLocalize->AddFile( "resource/replay_%language%.txt", "GAME" );
			g_pVGuiLocalize->AddFile( "resource/youtube_%language%.txt", "GAME" );
		}
	}
#endif
}

//----------------------------------------------------------------------------------------

void ReplaySystem_Shutdown()
{
#if defined( REPLAY_ENABLED )
	if ( g_pReplay )
	{
		// Shutdown the DLL
		g_pReplay->Shutdown();
		g_pReplay = NULL;
	}

	if ( gs_hReplayModule )
	{
		// Unload the DLL
		Sys_UnloadModule( gs_hReplayModule );
		gs_hReplayModule = NULL;
	}
#endif
}

//----------------------------------------------------------------------------------------

bool Replay_IsSupportedModAndPlatform()
{
	if ( !IsPC() )
		return false;

	int nNumSupportedReplayGames = ARRAYSIZE( s_pSupportedReplayGames );
	for ( int i = 0; i < nNumSupportedReplayGames; ++i )
	{
		const char *pCurGame = s_pSupportedReplayGames[ i ];
		if ( !Q_stricmp( COM_GetModDirectory(), pCurGame ) )
			return true;
	}
	return false;
}

//----------------------------------------------------------------------------------------