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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Interface for makefiles to build differently depending on where they are run from
//
//===========================================================================//
#ifndef DMEMAKEFILEUTILS_H
#define DMEMAKEFILEUTILS_H
#ifdef _WIN32
#pragma once
#endif
#include "movieobjects/idmemakefileutils.h"
#include "datamodel/dmehandle.h"
#include "tier1/utlsymbol.h"
#include "tier3/tier3.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CDmeMakefileUtils;
class CDmeMDLMakefile;
class CDmeMayaMakefile;
class CDmeSourceMayaFile;
class CDmeMakefile;
//-----------------------------------------------------------------------------
//
// This glue code here is to make it easy to create methods using various DmElement types
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Compilation steps
//-----------------------------------------------------------------------------
enum CompilationStep_t
{
BUILDING_STANDARD_DEPENDENCIES = 0,
BUILDING_ALL_DEPENDENCIES,
BEFORE_COMPILATION,
PERFORMING_COMPILATION,
AFTER_COMPILATION_FAILED,
AFTER_COMPILATION_SUCCEEDED,
NOT_COMPILING,
};
//-----------------------------------------------------------------------------
// Utility adapter class to hook compile funcs into the map
//-----------------------------------------------------------------------------
class CCompileFuncAdapterBase
{
public:
virtual void InitializeAdapter( ) = 0;
virtual bool PerformCompilationStep( CDmElement *pElement, CompilationStep_t step ) = 0;
protected:
// Constructor, protected because these should never be instanced directly
CCompileFuncAdapterBase( ) {}
public:
CUtlSymbol m_ElementType;
CCompileFuncAdapterBase *m_pNext;
};
template< class U, class T >
class CCompileFuncAdapter : public CCompileFuncAdapterBase
{
typedef CCompileFuncAdapterBase BaseClass;
public:
CCompileFuncAdapter( )
{
// Hook into the list
m_pNext = U::m_CompileFuncTree.m_pFirstAdapter;
U::m_CompileFuncTree.m_pFirstAdapter = this;
}
virtual void InitializeAdapter( )
{
m_ElementType = T::GetStaticTypeSymbol();
if ( m_pNext )
{
m_pNext->InitializeAdapter();
}
}
virtual bool PerformCompilationStep( CDmElement *pElement, CompilationStep_t step )
{
T *pConverted = CastElement< T >( pElement );
if ( pConverted )
return U::m_pSingleton->PerformCompilationStep( pConverted, step );
return false;
}
};
//-----------------------------------------------------------------------------
// Utility adapter class to hook editor opening funcs into the map
//-----------------------------------------------------------------------------
class COpenEditorFuncAdapterBase
{
public:
virtual void InitializeAdapter( ) = 0;
virtual void OpenEditor( CDmElement *pElement ) = 0;
protected:
// Constructor, protected because these should never be instanced directly
COpenEditorFuncAdapterBase( ) {}
public:
CUtlSymbol m_ElementType;
COpenEditorFuncAdapterBase *m_pNext;
};
template< class U, class T >
class COpenEditorFuncAdapter : public COpenEditorFuncAdapterBase
{
typedef COpenEditorFuncAdapterBase BaseClass;
public:
COpenEditorFuncAdapter( )
{
// Hook into the list
m_pNext = U::m_OpenEditorFuncTree.m_pFirstAdapter;
U::m_OpenEditorFuncTree.m_pFirstAdapter = this;
}
virtual void InitializeAdapter( )
{
m_ElementType = T::GetStaticTypeSymbol();
if ( m_pNext )
{
m_pNext->InitializeAdapter();
}
}
virtual void OpenEditor( CDmElement *pElement )
{
T *pConverted = CastElement< T >( pElement );
if ( pConverted )
{
U::m_pSingleton->OpenEditor( pConverted );
}
}
};
#define DECLARE_DMEMAKEFILE_UTIL_CLASS_BASE( _className ) \
protected: \
typedef _className ThisClass; \
static CompileFuncTree_t m_CompileFuncTree; \
static OpenEditorFuncTree_t m_OpenEditorFuncTree; \
static _className *m_pSingleton; \
template< typename U, typename T > friend class CCompileFuncAdapter; \
template< typename U, typename T > friend class COpenEditorFuncAdapter; \
virtual CompileFuncTree_t* GetCompileTree() \
{ \
return &m_CompileFuncTree; \
} \
virtual OpenEditorFuncTree_t* GetOpenEditorTree() \
{ \
return &m_OpenEditorFuncTree; \
} \
#define DECLARE_DMEMAKEFILE_UTIL_CLASS( _className, _baseClass ) \
DECLARE_DMEMAKEFILE_UTIL_CLASS_BASE( _className ) \
typedef _baseClass BaseClass; \
protected: \
virtual void InitializeFuncMaps() \
{ \
m_pSingleton = this; \
m_CompileFuncTree.m_pBaseAdapterTree = &BaseClass::m_CompileFuncTree; \
m_CompileFuncTree.m_pFirstAdapter->InitializeAdapter( ); \
m_OpenEditorFuncTree.m_pBaseAdapterTree = &BaseClass::m_OpenEditorFuncTree; \
m_OpenEditorFuncTree.m_pFirstAdapter->InitializeAdapter( ); \
BaseClass::InitializeFuncMaps(); \
} \
#define DECLARE_DMEMAKEFILE_UTIL_CLASS_ROOT( _className ) \
DECLARE_DMEMAKEFILE_UTIL_CLASS_BASE( _className ) \
protected: \
virtual void InitializeFuncMaps() \
{ \
m_pSingleton = this; \
m_CompileFuncTree.m_pBaseAdapterTree = NULL; \
m_CompileFuncTree.m_pFirstAdapter->InitializeAdapter( ); \
m_OpenEditorFuncTree.m_pBaseAdapterTree = NULL; \
m_OpenEditorFuncTree.m_pFirstAdapter->InitializeAdapter( ); \
} \
#define IMPLEMENT_DMEMAKEFILE_UTIL_CLASS( _className ) \
CDmeMakefileUtils::CompileFuncTree_t _className::m_CompileFuncTree; \
CDmeMakefileUtils::OpenEditorFuncTree_t _className::m_OpenEditorFuncTree; \
_className *_className::m_pSingleton; \
#define DECLARE_COMPILEFUNC( _className ) \
bool PerformCompilationStep( _className *pClassName, CompilationStep_t step ); \
CCompileFuncAdapter< ThisClass, _className > m_##_className##CompileAdapter
#define DECLARE_OPENEDITORFUNC( _className ) \
void OpenEditor( _className *pClassName ); \
COpenEditorFuncAdapter< ThisClass, _className > m_##_className##OpenEditorAdapter
//-----------------------------------------------------------------------------
// Interface for makefiles to build differently depending on where they are run from
//-----------------------------------------------------------------------------
class CDmeMakefileUtils : public CTier3AppSystem<IDmeMakefileUtils>
{
protected:
struct CompileFuncTree_t
{
CCompileFuncAdapterBase *m_pFirstAdapter;
CompileFuncTree_t *m_pBaseAdapterTree;
};
struct OpenEditorFuncTree_t
{
COpenEditorFuncAdapterBase *m_pFirstAdapter;
OpenEditorFuncTree_t *m_pBaseAdapterTree;
};
typedef CTier3AppSystem< IDmeMakefileUtils > BaseClass;
DECLARE_DMEMAKEFILE_UTIL_CLASS_ROOT( CDmeMakefileUtils );
public:
// Constructor, destructor
CDmeMakefileUtils();
virtual ~CDmeMakefileUtils();
// Inherited from IAppSystem
virtual void *QueryInterface( const char *pInterfaceName );
virtual InitReturnVal_t Init();
// Inherited from IDmeMakefileUtils
virtual void PerformCompile( CDmElement *pElement, bool bBuildAllDependencies );
virtual bool IsCurrentlyCompiling( );
virtual int GetCompileOutputSize();
virtual CompilationState_t UpdateCompilation( char *pOutputBuf, int nBufLen );
virtual void AbortCurrentCompilation();
virtual void PerformOpenEditor( CDmElement *pElement );
virtual int GetExitCode();
protected:
// Compile functions + editor functions
DECLARE_COMPILEFUNC( CDmElement );
DECLARE_COMPILEFUNC( CDmeMakefile );
DECLARE_COMPILEFUNC( CDmeMDLMakefile );
DECLARE_COMPILEFUNC( CDmeMayaMakefile );
DECLARE_OPENEDITORFUNC( CDmeSourceMayaFile );
// Queues up a compilation task
// ( Call only in BUILDING_STANDARD_DEPENDENCIES or BUILDING_ALL_DEPENDENCIES )
void AddCompilationTask( CDmElement* pElement );
// Sets the compilation process handle
// ( Call only in PERFORMING_COMPILATION )
void SetCompileProcess( ProcessHandle_t hProcess );
private:
struct CompileInfo_t
{
CDmeHandle< CDmElement > m_hElement;
CCompileFuncAdapterBase *m_pAdapter;
};
// Finds the adapter class associated with a particular element type
CCompileFuncAdapterBase *DetermineCompileAdapter( CDmElement *pElement );
COpenEditorFuncAdapterBase *DetermineOpenEditorAdapter( CDmElement *pElement );
// Dequeue the first compile task and start it up
void StartNextCompileTask();
// Performs the compilation step on all elements
bool PerformCompilationStep( CompilationStep_t step );
// Queues up a compilation task
void AddCompilationTask( CDmElement* pElement, CCompileFuncAdapterBase *pAdapter );
// Default implementatations for compile dependencies
bool AddCompileDependencies( CDmeMakefile *pMakefile, bool bBuildAllDependencies );
CUtlVector< CompileInfo_t > m_CompileTasks;
ProcessHandle_t m_hCompileProcess;
int m_nCurrentCompileTask;
int m_nExitCode;
CompilationStep_t m_CompilationStep;
};
#endif // DMEMAKEFILEUTILS_H
|