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.

83 lines
2.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A global class that holds a prioritized queue of entity I/O events.
  4. // Events can be posted with a nonzero delay, which determines how long
  5. // they are held before being dispatched to their recipients.
  6. //
  7. // The queue is serviced once per server frame.
  8. //
  9. //=============================================================================//
  10. #ifndef EVENTQUEUE_H
  11. #define EVENTQUEUE_H
  12. #ifdef _WIN32
  13. #pragma once
  14. #endif
  15. #include "mempool.h"
  16. struct EventQueuePrioritizedEvent_t
  17. {
  18. float m_flFireTime;
  19. string_t m_iTarget;
  20. string_t m_iTargetInput;
  21. EHANDLE m_pActivator;
  22. EHANDLE m_pCaller;
  23. int m_iOutputID;
  24. EHANDLE m_pEntTarget; // a pointer to the entity to target; overrides m_iTarget
  25. variant_t m_VariantValue; // variable-type parameter
  26. EventQueuePrioritizedEvent_t *m_pNext;
  27. EventQueuePrioritizedEvent_t *m_pPrev;
  28. DECLARE_SIMPLE_DATADESC();
  29. DECLARE_FIXEDSIZE_ALLOCATOR( PrioritizedEvent_t );
  30. };
  31. class CEventQueue
  32. {
  33. public:
  34. // pushes an event into the queue, targeting a string name (m_iName), or directly by a pointer
  35. void AddEvent( const char *target, const char *action, variant_t Value, float fireDelay, CBaseEntity *pActivator, CBaseEntity *pCaller, int outputID = 0 );
  36. void AddEvent( CBaseEntity *target, const char *action, float fireDelay, CBaseEntity *pActivator, CBaseEntity *pCaller, int outputID = 0 );
  37. void AddEvent( CBaseEntity *target, const char *action, variant_t Value, float fireDelay, CBaseEntity *pActivator, CBaseEntity *pCaller, int outputID = 0 );
  38. void CancelEvents( CBaseEntity *pCaller );
  39. void CancelEventOn( CBaseEntity *pTarget, const char *sInputName );
  40. bool HasEventPending( CBaseEntity *pTarget, const char *sInputName );
  41. // services the queue, firing off any events who's time hath come
  42. void ServiceEvents( void );
  43. // debugging
  44. void ValidateQueue( void );
  45. // serialization
  46. int Save( ISave &save );
  47. int Restore( IRestore &restore );
  48. CEventQueue();
  49. ~CEventQueue();
  50. void Init( void );
  51. void Clear( void ); // resets the list
  52. void Dump( void );
  53. private:
  54. void AddEvent( EventQueuePrioritizedEvent_t *event );
  55. void RemoveEvent( EventQueuePrioritizedEvent_t *pe );
  56. DECLARE_SIMPLE_DATADESC();
  57. EventQueuePrioritizedEvent_t m_Events;
  58. int m_iListCount;
  59. };
  60. extern CEventQueue g_EventQueue;
  61. #endif // EVENTQUEUE_H