blob: e05a50019e76f4e88db8650b8cd1acf5e3faa699 (
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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Deals with singleton
//
// $Revision: $
// $NoKeywords: $
//=============================================================================//
#if !defined( CLIENTEFFECTPRECACHESYSTEM_H )
#define CLIENTEFFECTPRECACHESYSTEM_H
#ifdef _WIN32
#pragma once
#endif
#include "igamesystem.h"
#include "commonmacros.h"
#include "utlvector.h"
#include "materialsystem/imaterialsystem.h"
#include "materialsystem/imaterial.h"
//-----------------------------------------------------------------------------
// Interface to automated system for precaching materials
//-----------------------------------------------------------------------------
class IClientEffect
{
public:
virtual void Cache( bool precache = true ) = 0;
};
//-----------------------------------------------------------------------------
// Responsible for managing precaching of particles
//-----------------------------------------------------------------------------
class CClientEffectPrecacheSystem : public IGameSystem
{
public:
virtual char const *Name() { return "CCLientEffectPrecacheSystem"; }
virtual bool IsPerFrame() { return false; }
// constructor, destructor
CClientEffectPrecacheSystem() {}
virtual ~CClientEffectPrecacheSystem() {}
// Init, shutdown
virtual bool Init() { return true; }
virtual void PostInit() {}
virtual void Shutdown();
// Level init, shutdown
virtual void LevelInitPreEntity();
virtual void LevelInitPostEntity() {}
virtual void LevelShutdownPreEntity();
virtual void LevelShutdownPostEntity();
virtual void OnSave() {}
virtual void OnRestore() {}
virtual void SafeRemoveIfDesired() {}
void Register( IClientEffect *effect );
protected:
CUtlVector< IClientEffect * > m_Effects;
};
//Singleton accessor
extern CClientEffectPrecacheSystem *ClientEffectPrecacheSystem();
//-----------------------------------------------------------------------------
// Deals with automated registering and precaching of materials for effects
//-----------------------------------------------------------------------------
class CClientEffect : public IClientEffect
{
public:
CClientEffect( void )
{
//Register with the main effect system
ClientEffectPrecacheSystem()->Register( this );
}
//-----------------------------------------------------------------------------
// Purpose: Precache a material by artificially incrementing its reference counter
// Input : *materialName - name of the material
// : increment - whether to increment or decrement the reference counter
//-----------------------------------------------------------------------------
inline void ReferenceMaterial( const char *materialName, bool increment = true )
{
IMaterial *material = materials->FindMaterial( materialName, TEXTURE_GROUP_CLIENT_EFFECTS );
if ( !IsErrorMaterial( material ) )
{
if ( increment )
{
material->IncrementReferenceCount();
}
else
{
material->DecrementReferenceCount();
}
}
}
};
//Automatic precache macros
//Beginning
#define CLIENTEFFECT_REGISTER_BEGIN( className ) \
namespace className { \
class ClientEffectRegister : public CClientEffect \
{ \
private: \
static const char *m_pszMaterials[]; \
public: \
void Cache( bool precache = true ); \
}; \
const char *ClientEffectRegister::m_pszMaterials[] = {
//Material definitions
#define CLIENTEFFECT_MATERIAL( materialName ) materialName,
//End
#define CLIENTEFFECT_REGISTER_END( ) }; \
void ClientEffectRegister::Cache( bool precache ) \
{ \
for ( int i = 0; i < ARRAYSIZE( m_pszMaterials ); i++ ) \
{ \
ReferenceMaterial( m_pszMaterials[i], precache ); \
} \
} \
ClientEffectRegister register_ClientEffectRegister; \
}
#define CLIENTEFFECT_REGISTER_END_CONDITIONAL(condition ) }; \
void ClientEffectRegister::Cache( bool precache ) \
{ \
if ( condition) \
{ \
for ( int i = 0; i < ARRAYSIZE( m_pszMaterials ); i++ ) \
{ \
ReferenceMaterial( m_pszMaterials[i], precache ); \
} \
} \
} \
ClientEffectRegister register_ClientEffectRegister; \
}
#endif //CLIENTEFFECTPRECACHESYSTEM_H
|