Team Fortress 2 Source Code as on 22/4/2020
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.

103 lines
3.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A simple test entity for creating special effects
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "te_effect_dispatch.h"
  8. // Declare the sparkler entity for the server-side
  9. class CSparkler : public CBaseEntity
  10. {
  11. public:
  12. DECLARE_SERVERCLASS();
  13. DECLARE_CLASS( CSparkler, CBaseEntity );
  14. void Spawn( void );
  15. void InputToggle( inputdata_t &input ); // Input function for toggling our effect's state
  16. void InputScale( inputdata_t &input );
  17. private:
  18. CNetworkVar( bool, m_bEmit ); // Marks whether the effect should be active or not
  19. CNetworkVar( float, m_flScale ); // The size and speed of the effect
  20. DECLARE_DATADESC();
  21. };
  22. // Link our class to the "env_sparkler" entity classname
  23. LINK_ENTITY_TO_CLASS( env_sparkler, CSparkler );
  24. // Declare our data description for this entity
  25. BEGIN_DATADESC( CSparkler )
  26. DEFINE_FIELD( m_bEmit, FIELD_BOOLEAN ),
  27. DEFINE_KEYFIELD( m_flScale, FIELD_FLOAT, "scale" ),
  28. DEFINE_INPUTFUNC( FIELD_VOID, "Toggle", InputToggle ), // Declare our toggle input function
  29. DEFINE_INPUTFUNC( FIELD_FLOAT, "Scale", InputScale ),
  30. END_DATADESC()
  31. // Declare the data-table for server/client communication
  32. IMPLEMENT_SERVERCLASS_ST( CSparkler, DT_Sparkler )
  33. SendPropInt( SENDINFO( m_bEmit ), 1, SPROP_UNSIGNED ), // Declare our boolean state variable
  34. SendPropFloat( SENDINFO( m_flScale ), 0, SPROP_NOSCALE ),
  35. END_SEND_TABLE()
  36. //-----------------------------------------------------------------------------
  37. // Purpose: Spawn function for this entity
  38. //-----------------------------------------------------------------------------
  39. void CSparkler::Spawn( void )
  40. {
  41. SetMoveType( MOVETYPE_NONE ); // Will not move on its own
  42. SetSolid( SOLID_NONE ); // Will not collide with anything
  43. // Set a size for culling
  44. UTIL_SetSize( this, -Vector(2,2,2), Vector(2,2,2) );
  45. // We must add this flag to receive network transmitions
  46. AddEFlags( EFL_FORCE_CHECK_TRANSMIT );
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose: Toggles the emission state of the effect
  50. //-----------------------------------------------------------------------------
  51. void CSparkler::InputToggle( inputdata_t &input )
  52. {
  53. // Toggle our state
  54. m_bEmit = !m_bEmit;
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Purpose: Change our scale via a float value
  58. //-----------------------------------------------------------------------------
  59. void CSparkler::InputScale( inputdata_t &input )
  60. {
  61. // Change our scale
  62. m_flScale = input.value.Float();
  63. }
  64. // ============================================================================
  65. //
  66. // Dispatch Effect version
  67. //
  68. // ============================================================================
  69. //-----------------------------------------------------------------------------
  70. // Purpose: Create a sparkle effect at the given location of the given size
  71. // Input : &position - Where to emit from
  72. // flSize - Size of the effect
  73. //-----------------------------------------------------------------------------
  74. void MakeSparkle( const Vector &origin, float flScale )
  75. {
  76. CEffectData data;
  77. // Send our origin
  78. data.m_vOrigin = origin;
  79. // Send our scale
  80. data.m_flScale = flScale;
  81. // Send the effect off to the client
  82. DispatchEffect( "Sparkle", data );
  83. }