Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
5.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "baseanimating.h"
  9. #include "SkyCamera.h"
  10. #include "studio.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. // HACK HACK: Must match cl_dll/cl_animevent.h!!!!
  14. #define CL_EVENT_SPRITEGROUP_CREATE 6002
  15. //-----------------------------------------------------------------------------
  16. // An entity which emits other entities at points
  17. //-----------------------------------------------------------------------------
  18. class CEnvParticleScript : public CBaseAnimating
  19. {
  20. public:
  21. DECLARE_CLASS( CEnvParticleScript, CBaseAnimating );
  22. DECLARE_SERVERCLASS();
  23. DECLARE_DATADESC();
  24. CEnvParticleScript();
  25. virtual void Precache();
  26. virtual void Spawn();
  27. virtual void Activate();
  28. virtual int UpdateTransmitState();
  29. void InputSetSequence( inputdata_t &inputdata );
  30. private:
  31. void PrecacheAnimationEventMaterials();
  32. CNetworkVar( float, m_flSequenceScale );
  33. };
  34. //-----------------------------------------------------------------------------
  35. // Save/load
  36. //-----------------------------------------------------------------------------
  37. BEGIN_DATADESC( CEnvParticleScript )
  38. DEFINE_FIELD( m_flSequenceScale, FIELD_FLOAT ),
  39. // Inputs
  40. DEFINE_INPUTFUNC( FIELD_STRING, "SetSequence", InputSetSequence ),
  41. END_DATADESC()
  42. LINK_ENTITY_TO_CLASS( env_particlescript, CEnvParticleScript );
  43. //-----------------------------------------------------------------------------
  44. // Datatable
  45. //-----------------------------------------------------------------------------
  46. IMPLEMENT_SERVERCLASS_ST( CEnvParticleScript, DT_EnvParticleScript )
  47. SendPropFloat(SENDINFO(m_flSequenceScale), 0, SPROP_NOSCALE),
  48. END_SEND_TABLE()
  49. //-----------------------------------------------------------------------------
  50. // Constructor
  51. //-----------------------------------------------------------------------------
  52. CEnvParticleScript::CEnvParticleScript()
  53. {
  54. UseClientSideAnimation();
  55. }
  56. void CEnvParticleScript::PrecacheAnimationEventMaterials()
  57. {
  58. CStudioHdr *hdr = GetModelPtr();
  59. if ( hdr )
  60. {
  61. int numseq = hdr->GetNumSeq();
  62. for ( int i = 0; i < numseq; ++i )
  63. {
  64. mstudioseqdesc_t& seqdesc = hdr->pSeqdesc( i );
  65. int ecount = seqdesc.numevents;
  66. for ( int j = 0 ; j < ecount; ++j )
  67. {
  68. const mstudioevent_t* event = (const mstudioevent_for_client_server_t*)seqdesc.pEvent( j );
  69. if ( event->Event() == CL_EVENT_SPRITEGROUP_CREATE )
  70. {
  71. char pAttachmentName[256];
  72. char pSpriteName[256];
  73. int nArgs = sscanf( event->pszOptions(), "%255s %255s", pAttachmentName, pSpriteName );
  74. if ( nArgs == 2 )
  75. {
  76. PrecacheMaterial( pSpriteName );
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Precache
  85. //-----------------------------------------------------------------------------
  86. void CEnvParticleScript::Precache()
  87. {
  88. BaseClass::Precache();
  89. PrecacheModel( STRING( GetModelName() ) );
  90. // We need a model for its animation sequences even though we don't render it
  91. SetModel( STRING( GetModelName() ) );
  92. PrecacheAnimationEventMaterials();
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Spawn
  96. //-----------------------------------------------------------------------------
  97. void CEnvParticleScript::Spawn()
  98. {
  99. Precache();
  100. BaseClass::Spawn();
  101. AddEffects( EF_NOSHADOW );
  102. // We need a model for its animation sequences even though we don't render it
  103. SetModel( STRING( GetModelName() ) );
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Activate
  107. //-----------------------------------------------------------------------------
  108. void CEnvParticleScript::Activate()
  109. {
  110. BaseClass::Activate();
  111. DetectInSkybox();
  112. CSkyCamera *pCamera = GetEntitySkybox();
  113. if ( pCamera )
  114. {
  115. float flSkyboxScale = pCamera->m_skyboxData.scale;
  116. if ( flSkyboxScale == 0.0f )
  117. {
  118. flSkyboxScale = 1.0f;
  119. }
  120. m_flSequenceScale = flSkyboxScale;
  121. }
  122. else
  123. {
  124. m_flSequenceScale = 1.0f;
  125. }
  126. m_flPlaybackRate = 1.0f;
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Should we transmit it to the client?
  130. //-----------------------------------------------------------------------------
  131. int CEnvParticleScript::UpdateTransmitState()
  132. {
  133. if ( IsEffectActive( EF_NODRAW ) )
  134. {
  135. return SetTransmitState( FL_EDICT_DONTSEND );
  136. }
  137. if ( IsEFlagSet( EFL_IN_SKYBOX ) )
  138. {
  139. return SetTransmitState( FL_EDICT_ALWAYS );
  140. }
  141. return SetTransmitState( FL_EDICT_PVSCHECK );
  142. }
  143. //-----------------------------------------------------------------------------
  144. // Purpose: Input that sets the sequence of the entity
  145. //-----------------------------------------------------------------------------
  146. void CEnvParticleScript::InputSetSequence( inputdata_t &inputdata )
  147. {
  148. if ( inputdata.value.StringID() != NULL_STRING )
  149. {
  150. int nSequence = LookupSequence( STRING( inputdata.value.StringID() ) );
  151. if ( nSequence != ACT_INVALID )
  152. {
  153. SetSequence( nSequence );
  154. }
  155. }
  156. }