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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Texture management functions. Exposes a list of available textures,
// texture groups, and Most Recently Used textures.
//
//=============================================================================//
#ifndef TEXTURESYSTEM_H
#define TEXTURESYSTEM_H
#ifdef _WIN32
#pragma once
#endif
#include "IEditorTexture.h"
#include "Material.h"
#include "utlvector.h"
#include "utldict.h"
#include "FileChangeWatcher.h"
class CGameConfig;
class CTextureSystem;
//-----------------------------------------------------------------------------
// Purpose: Defines the interface to a set of textures of a given texture format.
// The textures are stored as an index into the global array of textures.
//-----------------------------------------------------------------------------
class CTextureGroup
{
public:
CTextureGroup(const char *pszName);
inline const char *GetName()
{
return(m_szName);
}
inline int GetCount(void)
{
return m_Textures.Count();
}
inline TEXTUREFORMAT GetTextureFormat(void)
{
return(m_eTextureFormat);
}
inline void SetTextureFormat(TEXTUREFORMAT eTextureFormat)
{
m_eTextureFormat = eTextureFormat;
}
void AddTexture(IEditorTexture *pTexture);
void Sort(void);
IEditorTexture *GetTexture(int nIndex);
IEditorTexture* GetTexture( char const* pName );
// Fast find texture..
IEditorTexture* FindTextureByName( const char *pName, int *piIndex, TEXTUREFORMAT eDesiredFormat );
// Used to lazily load in all the textures
void LazyLoadTextures();
protected:
char m_szName[MAX_PATH];
TEXTUREFORMAT m_eTextureFormat;
CUtlVector<IEditorTexture *> m_Textures;
CUtlDict<int,int> m_TextureNameMap; // Maps the texture name to an index into m_Textures (the key is IEditorTexture::GetName).
// Used to lazily load the textures in the group
int m_nTextureToLoad;
};
typedef CUtlVector<CTextureGroup *> TextureGroupList_t;
typedef struct tagGF
{
char filename[MAX_PATH];
DWORD id;
int fd;
TEXTUREFORMAT format;
BOOL bLoaded;
} GRAPHICSFILESTRUCT;
//
// When the user switches game configs, all the textures and materials are switched.
// This structure holds all the context necessary to accomplish this.
//
struct TextureContext_t
{
CGameConfig *pConfig; // The game config that this texture context corresponds to.
CTextureGroup *pAllGroup;
TextureGroupList_t Groups;
EditorTextureList_t MRU; // List of Most Recently Used textures, first is the most recent.
EditorTextureList_t Dummies; // List of Dummy textures - textures that were created to hold the place of missing textures.
};
class CMaterialFileChangeWatcher : private CFileChangeWatcher::ICallbacks
{
public:
void Init( CTextureSystem *pSystem, int context );
void Update(); // Call this periodically to update.
private:
// CFileChangeWatcher::ICallbacks..
virtual void OnFileChange( const char *pRelativeFilename, const char *pFullFilename );
private:
CFileChangeWatcher m_Watcher;
CTextureSystem *m_pTextureSystem;
int m_Context;
};
class CTextureSystem : public IMaterialEnumerator
{
public:
friend class CMaterialFileChangeWatcher;
CTextureSystem(void);
virtual ~CTextureSystem(void);
bool Initialize(HWND hwnd);
void ShutDown(void);
void SetActiveConfig(CGameConfig *pConfig);
//
// Exposes a list of all texture (WAD) files.
//
inline int FilesGetCount(void) const;
inline void FilesGetInfo(GRAPHICSFILESTRUCT *pFileInfo, int nIndex) const;
bool FindGraphicsFile(GRAPHICSFILESTRUCT *pFileInfo, DWORD id, int *piIndex = NULL);
//
// Exposes a list of texture groups (sets of textures of a given format).
//
void SetActiveGroup(const char *pcszName);
inline int GroupsGetCount() const;
inline CTextureGroup *GroupsGet(int nIndex) const;
//
// Exposes a list of active textures based on the currently active texture group.
//
inline int GetActiveTextureCount(void) const;
inline IEditorTexture *GetActiveTexture(int nIndex) const;
IEditorTexture *EnumActiveTextures(int *piIndex, TEXTUREFORMAT eDesiredFormat) const;
IEditorTexture *FindActiveTexture(LPCSTR pszName, int *piIndex = NULL, BOOL bDummy = TRUE);
bool HasTexturesForConfig(CGameConfig *pConfig);
//
// Exposes a list of Most Recently Used textures.
//
void AddMRU(IEditorTexture *pTex);
inline int MRUGetCount() const;
inline IEditorTexture *MRUGet(int nIndex) const;
//
// Exposes a list of all unique keywords found in the master texture list.
//
int GetNumKeywords();
const char *GetKeyword(int index);
//
// Holds a list of placeholder textures used when a map refers to missing textures.
//
IEditorTexture *AddDummy(LPCTSTR pszName, TEXTUREFORMAT eFormat);
//
// Load graphics files from options list.
//
void LoadAllGraphicsFiles(void);
void InformPaletteChanged(void);
// IMaterialEnumerator interface, Used to add all the world materials into the material list.
bool EnumMaterial( const char *pMaterialName, int nContext );
// Used to lazily load in all the textures during app idle.
void LazyLoadTextures();
// Registers the keywords as existing in a particular material.
void RegisterTextureKeywords( IEditorTexture *pTexture );
// Opens the source file associated with a material.
void OpenSource( const char *pMaterialName );
// Reload individual textures.
void ReloadTextures( const char *pFilterName );
// bind local cubemap again
void RebindDefaultCubeMap();
void UpdateFileChangeWatchers();
// Gets tools/toolsnodraw
IEditorTexture* GetNoDrawTexture() { return m_pNoDrawTexture; }
int AddTexture( IEditorTexture *pTexture );
protected:
// CMaterialFileChangeWatcher stuff - watches for changes to VMTs or VTFs and handles them.
enum EFileType
{
k_eFileTypeVMT,
k_eFileTypeVTF
};
void OnFileChange( const char *pFilename, int context, EFileType eFileType );
void ReloadMaterialsUsingTexture( ITexture *pTestTexture );
static bool GetFileTypeFromFilename( const char *pFilename, CTextureSystem::EFileType *pFileType );
CUtlVector<CMaterialFileChangeWatcher*> m_ChangeWatchers;
// Internal stuff.
void FreeAllTextures();
TextureContext_t *AddTextureContext();
TextureContext_t *FindTextureContextForConfig(CGameConfig *pConfig);
void LoadMaterials(CGameConfig *pConfig);
void LoadWADFiles(CGameConfig *pConfig);
DWORD LoadGraphicsFile(const char *pFilename);
void LoadGraphicsFileWAD3(GRAPHICSFILESTRUCT *pFile, int fd, CTextureGroup *pGroup);
//
// Array of open graphics files.
//
CUtlVector<GRAPHICSFILESTRUCT> m_GraphicsFiles;
//
// Master array of textures.
//
CUtlVector<IEditorTexture *> m_Textures;
IEditorTexture *m_pLastTex;
int m_nLastIndex;
//
// List of groups (sets of textures of a given texture format). Only one
// group can be active at a time, based on the game configuration.
//
CUtlVector<TextureContext_t> m_TextureContexts; // One per game config.
TextureContext_t *m_pActiveContext; // Points to the active entry in m_TextureContexts.
CTextureGroup *m_pActiveGroup; // Points to the active entry in m_TextureContexts.
//
// List of keywords found in all textures.
//
CUtlVector<const char *> m_Keywords;
// default cubemap
ITexture *m_pCubemapTexture;
// tools/toolsnodraw
IEditorTexture* m_pNoDrawTexture;
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CTextureSystem::FilesGetCount(void) const
{
return(m_GraphicsFiles.Count());
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : pFileInfo -
// nIndex -
//-----------------------------------------------------------------------------
void CTextureSystem::FilesGetInfo(GRAPHICSFILESTRUCT *pFileInfo, int nIndex) const
{
if (pFileInfo != NULL)
{
*pFileInfo = m_GraphicsFiles[nIndex];
}
}
//-----------------------------------------------------------------------------
// Purpose: Returns the number of textures in the active group.
//-----------------------------------------------------------------------------
int CTextureSystem::GetActiveTextureCount(void) const
{
if (m_pActiveGroup != NULL)
{
return m_pActiveGroup->GetCount();
}
return(0);
}
IEditorTexture *CTextureSystem::GetActiveTexture(int nIndex) const
{
if (m_pActiveGroup != NULL)
{
return m_pActiveGroup->GetTexture(nIndex);
}
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CTextureSystem::GroupsGetCount() const
{
if (!m_pActiveContext)
return 0;
return m_pActiveContext->Groups.Count();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTextureGroup *CTextureSystem::GroupsGet(int nIndex) const
{
if (!m_pActiveContext)
return NULL;
return m_pActiveContext->Groups.Element(nIndex);
}
//-----------------------------------------------------------------------------
// Purpose: Initiates an iteration of the MRU list.
//-----------------------------------------------------------------------------
int CTextureSystem::MRUGetCount() const
{
if (!m_pActiveContext)
return NULL;
return m_pActiveContext->MRU.Count();
}
//-----------------------------------------------------------------------------
// Purpose: Returns the next texture in the MRU of the given format.
// Input : pos - Iterator.
// eDesiredFormat - Texture format to return.
// Output : Pointer to the texture.
//-----------------------------------------------------------------------------
IEditorTexture *CTextureSystem::MRUGet(int nIndex) const
{
if (!m_pActiveContext)
return NULL;
return m_pActiveContext->MRU.Element(nIndex);
}
extern CTextureSystem g_Textures;
#endif // TEXTURESYSTEM_H
|