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.

65 lines
1.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Simple logical entity that counts up to a threshold value, then
  4. // fires an output when reached.
  5. //
  6. //=============================================================================//
  7. #include "cbase.h"
  8. class CMyLogicalEntity : public CLogicalEntity
  9. {
  10. public:
  11. DECLARE_CLASS( CMyLogicalEntity , CLogicalEntity );
  12. DECLARE_DATADESC();
  13. // Constructor
  14. CMyLogicalEntity ( void ) : m_nCounter( 0 ) {}
  15. // Input function
  16. void InputTick( inputdata_t &inputData );
  17. private:
  18. int m_nThreshold; // Count at which to fire our output
  19. int m_nCounter; // Internal counter
  20. COutputEvent m_OnThreshold; // Output even when the counter reaches the threshold
  21. };
  22. LINK_ENTITY_TO_CLASS( my_logical_entity, CMyLogicalEntity );
  23. // Start of our data description for the class
  24. BEGIN_DATADESC( CMyLogicalEntity )
  25. // For save/load
  26. DEFINE_FIELD( m_nCounter, FIELD_INTEGER ),
  27. // Links our member variable to our keyvalue from Hammer
  28. DEFINE_KEYFIELD( m_nThreshold, FIELD_INTEGER, "threshold" ),
  29. // Links our input name from Hammer to our input member function
  30. DEFINE_INPUTFUNC( FIELD_VOID, "Tick", InputTick ),
  31. // Links our output member to the output name used by Hammer
  32. DEFINE_OUTPUT( m_OnThreshold, "OnThreshold" ),
  33. END_DATADESC()
  34. //-----------------------------------------------------------------------------
  35. // Purpose: Handle a tick input from another entity
  36. //-----------------------------------------------------------------------------
  37. void CMyLogicalEntity ::InputTick( inputdata_t &inputData )
  38. {
  39. // Increment our counter
  40. m_nCounter++;
  41. // See if we've met or crossed our threshold value
  42. if ( m_nCounter >= m_nThreshold )
  43. {
  44. // Fire an output event
  45. m_OnThreshold.FireOutput( inputData.pActivator, this );
  46. // Reset our counter
  47. m_nCounter = 0;
  48. }
  49. }