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.

110 lines
3.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "cbase.h"
  14. #include "basetempentity.h"
  15. #include "te_effect_dispatch.h"
  16. #include "networkstringtable_gamedll.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. //-----------------------------------------------------------------------------
  20. // Purpose: This TE provides a simple interface to dispatch effects by name using DispatchEffect().
  21. //-----------------------------------------------------------------------------
  22. class CTEEffectDispatch : public CBaseTempEntity
  23. {
  24. public:
  25. DECLARE_CLASS( CTEEffectDispatch, CBaseTempEntity );
  26. CTEEffectDispatch( const char *name );
  27. virtual ~CTEEffectDispatch( void );
  28. DECLARE_SERVERCLASS();
  29. public:
  30. CEffectData m_EffectData;
  31. };
  32. //-----------------------------------------------------------------------------
  33. // Purpose:
  34. // Input : *name -
  35. //-----------------------------------------------------------------------------
  36. CTEEffectDispatch::CTEEffectDispatch( const char *name ) :
  37. CBaseTempEntity( name )
  38. {
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose:
  42. //-----------------------------------------------------------------------------
  43. CTEEffectDispatch::~CTEEffectDispatch( void )
  44. {
  45. }
  46. IMPLEMENT_SERVERCLASS_ST( CTEEffectDispatch, DT_TEEffectDispatch )
  47. SendPropDataTable( SENDINFO_DT( m_EffectData ), &REFERENCE_SEND_TABLE( DT_EffectData ) )
  48. END_SEND_TABLE()
  49. // Singleton to fire TEEffectDispatch objects
  50. static CTEEffectDispatch g_TEEffectDispatch( "EffectDispatch" );
  51. //-----------------------------------------------------------------------------
  52. // Purpose:
  53. //-----------------------------------------------------------------------------
  54. void DispatchEffect( const char *pName, const CEffectData &data )
  55. {
  56. //Broadcast effects to all players. The potential for cheating
  57. //seems minimal on the effects that are sent through this,
  58. //and the overhead is minimal enough to make it worth sending to
  59. //all players.
  60. CReliableBroadcastRecipientFilter filter;
  61. filter.AddAllPlayers();
  62. if ( data.m_fFlags & EFFECTDATA_SERVER_IGNOREPREDICTIONCULL )
  63. {
  64. // remove prediction cull so it works on listen servers for the host
  65. filter.SetIgnorePredictionCull( true );
  66. }
  67. if ( !te->SuppressTE( filter ) )
  68. {
  69. // Copy the supplied effect data.
  70. g_TEEffectDispatch.m_EffectData = data;
  71. // Get the entry index in the string table.
  72. g_TEEffectDispatch.m_EffectData.m_iEffectName = GetEffectIndex( pName );
  73. // Send it to anyone who can see the effect's origin.
  74. g_TEEffectDispatch.Create( filter, 0 );
  75. }
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose:
  79. //-----------------------------------------------------------------------------
  80. void DispatchEffect( IRecipientFilter& filter, float flDelay, const char *pName, const CEffectData &data )
  81. {
  82. if ( !te->SuppressTE( filter ) )
  83. {
  84. // Copy the supplied effect data.
  85. g_TEEffectDispatch.m_EffectData = data;
  86. // Get the entry index in the string table.
  87. g_TEEffectDispatch.m_EffectData.m_iEffectName = GetEffectIndex( pName );
  88. // Send it to anyone who can see the effect's origin.
  89. g_TEEffectDispatch.Create( filter, flDelay );
  90. }
  91. }