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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//=======================================================================================//
#include "shared_replaycontext.h"
#include "replay/shared_defs.h"
#include "replay/replayutils.h"
#include "baserecordingsession.h"
#include "baserecordingsessionblock.h"
#include "baserecordingsessionmanager.h"
#include "baserecordingsessionblockmanager.h"
#include "thinkmanager.h"
#include "filesystem.h"
#include "errorsystem.h"
#undef Yield
#include "vstdlib/jobthread.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//----------------------------------------------------------------------------------------
CSharedReplayContext::CSharedReplayContext( IReplayContext *pOwnerContext )
: m_pOwnerContext( pOwnerContext ),
m_pRecordingSessionManager( NULL ),
m_pRecordingSessionBlockManager( NULL ),
m_pErrorSystem( NULL ),
m_pThreadPool( NULL ),
m_bInit( false )
{
}
CSharedReplayContext::~CSharedReplayContext()
{
delete m_pRecordingSessionManager;
delete m_pRecordingSessionBlockManager;
delete m_pErrorSystem;
delete m_pThreadPool;
}
bool CSharedReplayContext::Init( CreateInterfaceFn fnFactory )
{
m_strRelativeBasePath.Format(
"%s%c%s%c",
SUBDIR_REPLAY,
CORRECT_PATH_SEPARATOR,
m_strSubDir.Get(),
CORRECT_PATH_SEPARATOR
);
m_strBasePath.Format(
"%s%c%s",
g_pEngine->GetGameDir(),
CORRECT_PATH_SEPARATOR,
m_strRelativeBasePath.Get()
);
// Owning context should have initialized these by now
// NOTE: Session manager init must come after block manager init since session manager
// assumes all blocks have been loaded.
//
m_pRecordingSessionBlockManager->Init();
m_pRecordingSessionManager->Init();
if ( !InitThreadPool() )
return false;
m_bInit = true;
return true;
}
bool CSharedReplayContext::InitThreadPool()
{
// Create thread pool
Log( "Replay: Creating thread pool..." );
IThreadPool *pThreadPool = CreateThreadPool();
if ( !pThreadPool )
{
Log( "failed!\n" );
return false;
}
Log( "succeeded.\n" );
// Jon says: The client only really needs a single "ReplayContext" thread, so that the replay editor can write
// data asynchronously. The game server does in fact require 4 threads, and can be configured to use more
// via the replay_max_publish_threads convar.
int nMaxThreads = 1;
if ( g_pEngine->IsDedicated() )
{
// Use the convar for max threads on servers
extern ConVar replay_max_publish_threads;
nMaxThreads = replay_max_publish_threads.GetInt();
}
// Start thread pool
Log( "Replay: Starting thread pool with %i threads...", nMaxThreads );
if ( !pThreadPool->Start( ThreadPoolStartParams_t( true, nMaxThreads ), "ReplayContext" ) )
{
Log( "failed!\n" );
return false;
}
Log( "succeeded.\n" );
m_pThreadPool = pThreadPool;
return true;
}
void CSharedReplayContext::Shutdown()
{
m_pRecordingSessionBlockManager->Shutdown();
m_pRecordingSessionManager->Shutdown();
m_pThreadPool->Stop();
}
void CSharedReplayContext::Think()
{
}
const char *CSharedReplayContext::GetRelativeBaseDir() const
{
return m_strRelativeBasePath.Get();
}
const char *CSharedReplayContext::GetBaseDir() const
{
return m_strBasePath.Get();
}
const char *CSharedReplayContext::GetReplaySubDir() const
{
return m_strSubDir.Get();
}
void CSharedReplayContext::EnsureDirHierarchy()
{
g_pFullFileSystem->CreateDirHierarchy( m_strBasePath.Get() );
}
//----------------------------------------------------------------------------------------
bool RunJobToCompletion( IThreadPool *pThreadPool, CJob *pJob )
{
pThreadPool->AddJob( pJob );
pJob->WaitForFinish();
return pJob->Executed();
}
//----------------------------------------------------------------------------------------
|