aboutsummaryrefslogtreecommitdiff
path: root/sp/src/game/client/clienteffectprecachesystem.h
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
committerJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
commit39ed87570bdb2f86969d4be821c94b722dc71179 (patch)
treeabc53757f75f40c80278e87650ea92808274aa59 /sp/src/game/client/clienteffectprecachesystem.h
downloadsource-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz
source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip
First version of the SOurce SDK 2013
Diffstat (limited to 'sp/src/game/client/clienteffectprecachesystem.h')
-rw-r--r--sp/src/game/client/clienteffectprecachesystem.h150
1 files changed, 150 insertions, 0 deletions
diff --git a/sp/src/game/client/clienteffectprecachesystem.h b/sp/src/game/client/clienteffectprecachesystem.h
new file mode 100644
index 00000000..99cde9d4
--- /dev/null
+++ b/sp/src/game/client/clienteffectprecachesystem.h
@@ -0,0 +1,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