aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/client/replay/cdll_replay.cpp
blob: 618edfa72a4d0d4db6d734576a5859992c8b60e1 (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
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
//========= Copyright Valve Corporation, All rights reserved. ============//
#include "cbase.h"

#if defined( REPLAY_ENABLED )

#include "replay/cdll_replay.h"
#include "replay/replaycamera.h"
#include "replay/replay_ragdoll.h"
#include "replay/iclientreplay.h"
#include "replay/ireplayscreenshotsystem.h"
#include "replay/ireplaysystem.h"
#include "replay/ienginereplay.h"
#include "replay/ireplaymoviemanager.h"
#include "replay/vgui/replayconfirmquitdlg.h"
#include "replay/vgui/replaybrowsermainpanel.h"
#include "replay/vgui/replayinputpanel.h"
#include "replay/vgui/replayperformanceeditor.h"
#include "replayperformanceplaybackhandler.h"
#include "vgui/ILocalize.h"
#include "vgui/ISurface.h"
#include "clientmode.h"
#include "iviewrender.h"
#include "igameevents.h"
#include "replaycamera.h"
#if defined( TF_CLIENT_DLL )
#include "c_tf_gamestats.h"
#endif
#include "steamworks_gamestats.h"
#include "replay_gamestats_shared.h"

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

class IReplayScreenshotSystem;

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

extern void ReplayUI_OpenReplayRenderOverlay();
extern void ReplayUI_HideRenderOverlay();

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

extern IReplayMovieManager *g_pReplayMovieManager;

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

class CClientReplayImp : public IClientReplay
{
public:
	virtual uint64 GetServerSessionId()
	{
		return GetSteamWorksSGameStatsUploader().GetServerSessionID();
	}
	
	virtual IReplayScreenshotSystem *GetReplayScreenshotSystem()
	{
		if ( g_pEngineReplay->IsSupportedModAndPlatform() )
			return view->GetReplayScreenshotSystem();
		return NULL;
	}

	virtual IReplayPerformancePlaybackHandler *GetPerformancePlaybackHandler()
	{
		return g_pReplayPerformancePlaybackHandler;
	}

	virtual bool CacheReplayRagdolls( const char* pFilename, int nStartTick )
	{
		return Replay_CacheRagdolls( pFilename, nStartTick );
	}

	virtual void OnSaveReplay( ReplayHandle_t hNewReplay, bool bShowInputDlg )
	{
		if ( bShowInputDlg )
		{
			// Get a name for the replay, saves to disk, add thumbnail to replay browser
			ShowReplayInputPanel( hNewReplay );
		}
		else
		{
			// Just add the thumbnail if the replay browser exists
			CReplayBrowserPanel* pReplayBrowser = ReplayUI_GetBrowserPanel();
			if ( pReplayBrowser )
			{
				pReplayBrowser->OnSaveReplay( hNewReplay );
			}
		}

		// Fire a message the game DLL can intercept (for achievements, etc).
		IGameEvent *event = gameeventmanager->CreateEvent( "replay_saved" );
		if ( event )
		{
			gameeventmanager->FireEventClientSide( event );
		}
	}

	virtual void OnDeleteReplay( ReplayHandle_t hReplay )
	{
		CReplayBrowserPanel* pReplayBrowser = ReplayUI_GetBrowserPanel();
		if ( pReplayBrowser )
		{
			pReplayBrowser->OnDeleteReplay( hReplay );
		}
	}

	virtual void DisplayReplayMessage( const char *pLocalizeStr, bool bUrgent, bool bDlg, const char *pSound )
	{
		// Display a message?
		if ( !pLocalizeStr || !pLocalizeStr[0] )
			return;

		g_pClientMode->DisplayReplayMessage( pLocalizeStr, -1.0f, bUrgent, pSound, bDlg );
	}

	virtual void DisplayReplayMessage( const wchar_t *pText, bool bUrgent, bool bDlg, const char *pSound )
	{
		if ( !pText || !pText[0] )
			return;
	
		const int nLen = wcslen( pText ) + 1;
		char *pAnsi = new char[ nLen ];
		g_pVGuiLocalize->ConvertUnicodeToANSI( pText, pAnsi, nLen );

		g_pClientMode->DisplayReplayMessage( pAnsi, -1.0f, bUrgent, pSound, bDlg );
	}

	virtual bool OnConfirmQuit()
	{
		return ReplayUI_ShowConfirmQuitDlg();
	}

	virtual void OnRenderStart()
	{
		ReplayUI_OpenReplayRenderOverlay();
	}

	virtual void OnRenderComplete( const RenderMovieParams_t &RenderParams, bool bCancelled, bool bSuccess, bool bShowBrowser )
	{
		ReplayUI_HideRenderOverlay();

		if ( bShowBrowser )
		{
			ReplayUI_ReloadBrowser();
		}

		// Upload a row to the OGS now that rendering has completed
		GetReplayGameStatsHelper().SW_ReplayStats_WriteRenderDataEnd( RenderParams, bCancelled ? "cancelled" : bSuccess ? "success" : "failed" );
	}

	virtual void InitPerformanceEditor( ReplayHandle_t hReplay )
	{
		ReplayUI_InitPerformanceEditor( hReplay );
	}

	virtual void HidePerformanceEditor()
	{
		ReplayUI_ClosePerformanceEditor();
	}

	virtual bool ShouldRender()
	{
		extern ConVar replay_enablerenderpreview;
		return !g_pReplayMovieManager->IsRendering() || replay_enablerenderpreview.GetBool();
	}

	virtual void PlaySound( const char *pSound )
	{
		if ( g_pVGuiSurface )
		{
			g_pVGuiSurface->PlaySound( pSound );
		}
	}

	virtual void UploadOgsData( KeyValues *pData, bool bIncludeTimeField )
	{
		GetReplayGameStatsHelper().UploadError( pData, bIncludeTimeField );
	}

	virtual bool ShouldCompletePendingReplay( IGameEvent *pEvent )
	{
#if defined( TF_CLIENT_DLL )
		return !( pEvent->GetInt( "death_flags" ) & TF_DEATH_FEIGN_DEATH );
#else
		return true;
#endif
	}

	virtual void OnPlaybackComplete( ReplayHandle_t hReplay, int iPerformance )
	{
		ReplayUI_ReloadBrowser( hReplay, iPerformance );
	}

	virtual IReplayCamera *GetReplayCamera()
	{
		return ReplayCamera();
	}

	virtual bool OnEndOfReplayReached()
	{
		CReplayPerformanceEditorPanel *pEditor = ReplayUI_GetPerformanceEditor();
		if ( !pEditor )
			return false;

		return pEditor->OnEndOfReplayReached();
	}
};

static CClientReplayImp s_ClientReplayImp;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CClientReplayImp, IClientReplay, CLIENT_REPLAY_INTERFACE_VERSION, s_ClientReplayImp );

#endif	// #if defined( REPLAY_ENABLED )